| [bcf653] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
|  | 4 | * Copyright (C)  2010 University of Bonn. All rights reserved. | 
|---|
|  | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
| [aba92d] | 8 | /* | 
|---|
|  | 9 | * ActOnAllUnitTest.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: 04.10.2009 | 
|---|
|  | 12 | *      Author: FrederikHeber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [aba92d] | 20 | using namespace std; | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
| [46ea3b] | 26 | #include "../test/ActOnAlltest.hpp" | 
|---|
| [aba92d] | 27 | #include "ActOnAllUnitTest.hpp" | 
|---|
| [57f243] | 28 | #include "LinearAlgebra/Vector.hpp" | 
|---|
| [aba92d] | 29 |  | 
|---|
| [9b6b2f] | 30 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 31 | #include "UnitTestMain.hpp" | 
|---|
|  | 32 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 33 |  | 
|---|
| [aba92d] | 34 | /********************************************** Test classes **************************************/ | 
|---|
|  | 35 |  | 
|---|
|  | 36 | // Registers the fixture into the 'registry' | 
|---|
|  | 37 | CPPUNIT_TEST_SUITE_REGISTRATION( ActOnAllTest ); | 
|---|
|  | 38 |  | 
|---|
|  | 39 |  | 
|---|
|  | 40 | void ActOnAllTest::setUp() | 
|---|
|  | 41 | { | 
|---|
|  | 42 | Vector *temp = NULL; | 
|---|
|  | 43 | // fill list with vectors | 
|---|
|  | 44 | temp = new Vector(1,0,0); | 
|---|
|  | 45 | VL.AddVector(temp); | 
|---|
|  | 46 | temp = new Vector(0,1,0); | 
|---|
|  | 47 | VL.AddVector(temp); | 
|---|
|  | 48 | temp = new Vector(0,0,1); | 
|---|
|  | 49 | VL.AddVector(temp); | 
|---|
| [33f9f7] | 50 | Ref = VL; | 
|---|
| [aba92d] | 51 | }; | 
|---|
|  | 52 |  | 
|---|
|  | 53 |  | 
|---|
|  | 54 | void ActOnAllTest::tearDown() | 
|---|
|  | 55 | { | 
|---|
|  | 56 | VL.EmptyList(); | 
|---|
| [f72703] | 57 | // Ref was copy constructed, hence has to be cleaned, too! | 
|---|
|  | 58 | Ref.EmptyList(); | 
|---|
| [aba92d] | 59 | }; | 
|---|
|  | 60 |  | 
|---|
| [eaee7f] | 61 | /** UnitTest for VectorList::ActOnAll() and Vector::AddVector(), Vector::SubtractVector(), | 
|---|
| [33f9f7] | 62 | */ | 
|---|
|  | 63 | void ActOnAllTest::AddSubtractTest() | 
|---|
|  | 64 | { | 
|---|
|  | 65 | const Vector test(1.,0.,0.); | 
|---|
|  | 66 |  | 
|---|
|  | 67 | // adding, subtracting | 
|---|
| [273382] | 68 | VL.ActOnAll( &Vector::AddVector, test ); | 
|---|
| [33f9f7] | 69 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); | 
|---|
| [273382] | 70 | VL.ActOnAll( &Vector::SubtractVector, test ); | 
|---|
| [33f9f7] | 71 | CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); | 
|---|
|  | 72 | }; | 
|---|
|  | 73 |  | 
|---|
| [eaee7f] | 74 | /** UnitTest for VectorList::ActOnAll() | 
|---|
| [aba92d] | 75 | */ | 
|---|
| [33f9f7] | 76 | void ActOnAllTest::ScaleTest() | 
|---|
|  | 77 | { | 
|---|
|  | 78 | double factor=2.; | 
|---|
|  | 79 | double inverse=1./2.; | 
|---|
|  | 80 |  | 
|---|
|  | 81 | // scaling by value | 
|---|
| [1bd79e] | 82 | VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, factor ); | 
|---|
| [33f9f7] | 83 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); | 
|---|
|  | 84 |  | 
|---|
| [1bd79e] | 85 | VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, inverse ); | 
|---|
| [33f9f7] | 86 | CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); | 
|---|
|  | 87 |  | 
|---|
|  | 88 | // scaling by three values | 
|---|
| [920c70] | 89 | double *factors = new double[NDIM]; | 
|---|
|  | 90 | double *inverses = new double[NDIM]; | 
|---|
| [33f9f7] | 91 | for (int i=0;i<NDIM;++i) { | 
|---|
|  | 92 | factors[i] = 2.; | 
|---|
|  | 93 | inverses[i] = 1./factors[i]; | 
|---|
|  | 94 | } | 
|---|
| [1bd79e] | 95 | VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, factors ); | 
|---|
| [33f9f7] | 96 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); | 
|---|
|  | 97 |  | 
|---|
| [1bd79e] | 98 | VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses ); | 
|---|
| [33f9f7] | 99 | CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); | 
|---|
| [920c70] | 100 | delete[](factors); | 
|---|
|  | 101 | delete[](inverses); | 
|---|
| [33f9f7] | 102 | }; | 
|---|
|  | 103 |  | 
|---|
| [0a4f7f] | 104 | #if 0 | 
|---|
|  | 105 |  | 
|---|
|  | 106 | // Unitttest deactivated for now... | 
|---|
|  | 107 | // Reasons: | 
|---|
|  | 108 | //    Vector::MakeNormalVector has been removed and is now part of Plane class | 
|---|
|  | 109 | //    VectorList::ActOnAll is in the test directory and seems to be used only for unittests | 
|---|
|  | 110 | //    MakeNormal never depended on the input Vector except in the case of linear dependence (i.e. failure) | 
|---|
|  | 111 | // | 
|---|
|  | 112 | // TODO: Rethink what exactely is being tested at this point and introduce a new unittest for the | 
|---|
|  | 113 | //       tested behaviour. Most likely this should result in a thourough unittest of the plane class | 
|---|
|  | 114 |  | 
|---|
| [eaee7f] | 115 | /** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector() | 
|---|
| [33f9f7] | 116 | */ | 
|---|
|  | 117 | void ActOnAllTest::NormalizeTest() | 
|---|
| [aba92d] | 118 | { | 
|---|
| [33f9f7] | 119 | const Vector xaxis(1.,0.,0.); | 
|---|
|  | 120 | const Vector yaxis(0.,1.,0.); | 
|---|
|  | 121 |  | 
|---|
|  | 122 | // normalize with respect to x and y axis | 
|---|
|  | 123 | bool (Vector::*f)(const Vector *, const Vector *) = &Vector::MakeNormalVector; | 
|---|
| [eaee7f] | 124 | VL.ActOnAll( f, &xaxis, &yaxis ); | 
|---|
| [33f9f7] | 125 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); | 
|---|
|  | 126 |  | 
|---|
|  | 127 | // check that x and y components are zero | 
|---|
|  | 128 | for (ListOfVectors::iterator Runner = VL.Vectors.begin(); Runner != VL.Vectors.end(); Runner++) { | 
|---|
| [0a4f7f] | 129 | CPPUNIT_ASSERT_EQUAL( (*Runner)->at(0) , 0. ); | 
|---|
|  | 130 | CPPUNIT_ASSERT_EQUAL( (*Runner)->at(1) , 0. ); | 
|---|
| [33f9f7] | 131 | } | 
|---|
| [aba92d] | 132 | }; | 
|---|
| [0a4f7f] | 133 |  | 
|---|
|  | 134 | #endif | 
|---|