/*
 * Project: MoleCuilder
 * Description: creates and alters molecular systems
 * Copyright (C)  2012 University of Bonn. All rights reserved.
 * 
 *
 *   This file is part of MoleCuilder.
 *
 *    MoleCuilder is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    MoleCuilder is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with MoleCuilder.  If not, see .
 */
/*
 * SetValueMapUnitTest.cpp
 *
 *  Created on: Jul 4, 2012
 *      Author: heber
 */
// include config.h
#ifdef HAVE_CONFIG_H
#include 
#endif
using namespace std;
#include 
#include 
#include 
#include "Fragmentation/Summation/IndexSet.hpp"
#include "Fragmentation/Summation/IndexSetContainer.hpp"
#include "Fragmentation/Summation/SetValueMap.hpp"
#include "SetValueMapUnitTest.hpp"
#include 
#ifdef HAVE_TESTRUNNER
#include "UnitTestMain.hpp"
#endif /*HAVE_TESTRUNNER*/
using namespace boost::assign;
/********************************************** Test classes **************************************/
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( SetValueMapTest );
void SetValueMapTest::setUp()
{
}
void SetValueMapTest::tearDown()
{
}
/** UnitTest for addValue()
 */
void SetValueMapTest::addValueTest()
{
  IndexSet::ptr set(new IndexSet);
  *set += 1,2,3,4;
  CPPUNIT_ASSERT_EQUAL( (size_t)0, setmap.Lookup.size() );
  // adding once increases number of elements
  setmap.addValue(set, 4);
  CPPUNIT_ASSERT_EQUAL( (size_t)1, setmap.Lookup.size() );
  // adding set again does not introduce new element
  setmap.addValue(set, 5);
  CPPUNIT_ASSERT_EQUAL( (size_t)1, setmap.Lookup.size() );
}
/** UnitTest for getValue()
 */
void SetValueMapTest::getValueTest()
{
  IndexSet::ptr set(new IndexSet);
  *set += 1,2,3,4;
  setmap.addValue(set, 4);
  CPPUNIT_ASSERT_EQUAL( 4, setmap.getValue(set)->getValue() );
  setmap.addValue(set, 5);
  CPPUNIT_ASSERT_EQUAL( 5, setmap.getValue(set)->getValue() );
}
/** UnitTest for getValue()
 */
void SetValueMapTest::removeValueTest()
{
  IndexSet::ptr set(new IndexSet);
  *set += 1,2,3,4;
  IndexSet::ptr otherset(new IndexSet);
  *set += 1,2,3;
  setmap.addValue(set, 4);
  CPPUNIT_ASSERT_EQUAL( (size_t)1, setmap.Lookup.size() );
  // remove non-present set
  CPPUNIT_ASSERT( !setmap.removeValue(otherset) );
  CPPUNIT_ASSERT_EQUAL( (size_t)1, setmap.Lookup.size() );
  // remove present value
  CPPUNIT_ASSERT( setmap.removeValue(set) );
  CPPUNIT_ASSERT_EQUAL( (size_t)0, setmap.Lookup.size() );
  // re-add
  setmap.addValue(set, 4);
  CPPUNIT_ASSERT_EQUAL( (size_t)1, setmap.Lookup.size() );
}
/** UnitTest for iteration of internal map is working
 */
void SetValueMapTest::iteratorTest()
{
  SetValueMap::const_iterator iter = setmap.begin();
  CPPUNIT_ASSERT( iter == setmap.end() );
  IndexSet::ptr set(new IndexSet);
  *set += 1,2,3,4;
  setmap.addValue(set, 4);
  iter = setmap.begin();
  CPPUNIT_ASSERT( iter != setmap.end() );
  CPPUNIT_ASSERT_EQUAL (4,  iter->second->getValue());
}