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