/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * CacheableUnitTest.cpp * * Created on: Feb 2, 2010 * Author: crueger */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CacheableUnitTest.hpp" #include #include #include #include #include "Patterns/Cacheable.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( CacheableTest ); class threeNumbers : public Observable { public: int x; int y; int z; Cacheable sum; bool hasRecalced; void setX(int _x){ OBSERVE; x = _x; } void setY (int _y){ OBSERVE; y = _y; } void setZ(int _z){ OBSERVE; z = _z; } int calcSum(){ hasRecalced = true; return x+y+z; } threeNumbers(int _x,int _y, int _z) : Observable("threeNumbers"), x(_x),y(_y),z(_z), sum(this,boost::bind(&threeNumbers::calcSum,this),"sum"), hasRecalced(false) {} }; void CacheableTest::setUp(){ numbers = new threeNumbers(1,2,3); } void CacheableTest::tearDown(){ delete numbers; } void CacheableTest::doesRecalcTest() { CPPUNIT_ASSERT_EQUAL( 6, *(numbers->sum)); CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced); numbers->hasRecalced=false; numbers->setX(4); CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced); CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum)); CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced); numbers->hasRecalced=false; CPPUNIT_ASSERT_EQUAL( 9, *(numbers->sum)); #ifndef NO_CACHING CPPUNIT_ASSERT_EQUAL( false, numbers->hasRecalced); #else CPPUNIT_ASSERT_EQUAL( true, numbers->hasRecalced); #endif }