/* * ActOnAllUnitTest.cpp * * Created on: 04.10.2009 * Author: FrederikHeber */ using namespace std; #include #include #include #include "../test/ActOnAlltest.hpp" #include "ActOnAllUnitTest.hpp" #include "memoryallocator.hpp" #include "vector.hpp" /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( ActOnAllTest ); void ActOnAllTest::setUp() { Vector *temp = NULL; // fill list with vectors temp = new Vector(1,0,0); VL.AddVector(temp); temp = new Vector(0,1,0); VL.AddVector(temp); temp = new Vector(0,0,1); VL.AddVector(temp); Ref = VL; }; void ActOnAllTest::tearDown() { VL.EmptyList(); }; /** UnitTest for VectorList::ActOnAll() and Vector::AddVector(), Vector::SubtractVector(), */ void ActOnAllTest::AddSubtractTest() { const Vector test(1.,0.,0.); // adding, subtracting VL.ActOnAll( &Vector::AddVector, &test ); CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); VL.ActOnAll( &Vector::SubtractVector, &test ); CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); }; /** UnitTest for VectorList::ActOnAll() */ void ActOnAllTest::ScaleTest() { double factor=2.; double inverse=1./2.; // scaling by value VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 2. ); CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 0.5 ); CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); // scaling by ref VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&factor ); CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&inverse ); CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); // scaling by three values double *factors = Malloc(NDIM, "ActOnAllTest::ScaleTest - factors"); double *inverses = Malloc(NDIM, "ActOnAllTest::ScaleTest - inverses"); for (int i=0;ix[0] , 0. ); CPPUNIT_ASSERT_EQUAL( (*Runner)->x[1] , 0. ); } }; /********************************************** Main routine **************************************/ int main(int argc, char **argv) { // Get the top level suite from the registry CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); // Adds the test to the list of test to run CppUnit::TextUi::TestRunner runner; runner.addTest( suite ); // Change the default outputter to a compiler error format outputter runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) ); // Run the tests. bool wasSucessful = runner.run(); // Return error code 1 if the one of test failed. return wasSucessful ? 0 : 1; };