| 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 |
|
|---|
| 8 | /*
|
|---|
| 9 | * ActOnAllUnitTest.cpp
|
|---|
| 10 | *
|
|---|
| 11 | * Created on: 04.10.2009
|
|---|
| 12 | * Author: FrederikHeber
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | // include config.h
|
|---|
| 16 | #ifdef HAVE_CONFIG_H
|
|---|
| 17 | #include <config.h>
|
|---|
| 18 | #endif
|
|---|
| 19 |
|
|---|
| 20 | using namespace std;
|
|---|
| 21 |
|
|---|
| 22 | #include <cppunit/CompilerOutputter.h>
|
|---|
| 23 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
|---|
| 24 | #include <cppunit/ui/text/TestRunner.h>
|
|---|
| 25 |
|
|---|
| 26 | #include "../test/ActOnAlltest.hpp"
|
|---|
| 27 | #include "ActOnAllUnitTest.hpp"
|
|---|
| 28 | #include "LinearAlgebra/Vector.hpp"
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HAVE_TESTRUNNER
|
|---|
| 31 | #include "UnitTestMain.hpp"
|
|---|
| 32 | #endif /*HAVE_TESTRUNNER*/
|
|---|
| 33 |
|
|---|
| 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);
|
|---|
| 50 | Ref = VL;
|
|---|
| 51 | };
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | void ActOnAllTest::tearDown()
|
|---|
| 55 | {
|
|---|
| 56 | VL.EmptyList();
|
|---|
| 57 | // Ref was copy constructed, hence has to be cleaned, too!
|
|---|
| 58 | Ref.EmptyList();
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | /** UnitTest for VectorList::ActOnAll() and Vector::AddVector(), Vector::SubtractVector(),
|
|---|
| 62 | */
|
|---|
| 63 | void ActOnAllTest::AddSubtractTest()
|
|---|
| 64 | {
|
|---|
| 65 | const Vector test(1.,0.,0.);
|
|---|
| 66 |
|
|---|
| 67 | // adding, subtracting
|
|---|
| 68 | VL.ActOnAll( &Vector::AddVector, test );
|
|---|
| 69 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
|
|---|
| 70 | VL.ActOnAll( &Vector::SubtractVector, test );
|
|---|
| 71 | CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
|
|---|
| 72 | };
|
|---|
| 73 |
|
|---|
| 74 | /** UnitTest for VectorList::ActOnAll()
|
|---|
| 75 | */
|
|---|
| 76 | void ActOnAllTest::ScaleTest()
|
|---|
| 77 | {
|
|---|
| 78 | double factor=2.;
|
|---|
| 79 | double inverse=1./2.;
|
|---|
| 80 |
|
|---|
| 81 | // scaling by value
|
|---|
| 82 | VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, factor );
|
|---|
| 83 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
|
|---|
| 84 |
|
|---|
| 85 | VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, inverse );
|
|---|
| 86 | CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
|
|---|
| 87 |
|
|---|
| 88 | // scaling by three values
|
|---|
| 89 | double *factors = new double[NDIM];
|
|---|
| 90 | double *inverses = new double[NDIM];
|
|---|
| 91 | for (int i=0;i<NDIM;++i) {
|
|---|
| 92 | factors[i] = 2.;
|
|---|
| 93 | inverses[i] = 1./factors[i];
|
|---|
| 94 | }
|
|---|
| 95 | VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, factors );
|
|---|
| 96 | CPPUNIT_ASSERT_EQUAL( VL == Ref , false );
|
|---|
| 97 |
|
|---|
| 98 | VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses );
|
|---|
| 99 | CPPUNIT_ASSERT_EQUAL( VL == Ref , true );
|
|---|
| 100 | delete[](factors);
|
|---|
| 101 | delete[](inverses);
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 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 |
|
|---|
| 115 | /** UnitTest for VectorList::ActOnAll() and Vector::MakeNormalVector()
|
|---|
| 116 | */
|
|---|
| 117 | void ActOnAllTest::NormalizeTest()
|
|---|
| 118 | {
|
|---|
| 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;
|
|---|
| 124 | VL.ActOnAll( f, &xaxis, &yaxis );
|
|---|
| 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++) {
|
|---|
| 129 | CPPUNIT_ASSERT_EQUAL( (*Runner)->at(0) , 0. );
|
|---|
| 130 | CPPUNIT_ASSERT_EQUAL( (*Runner)->at(1) , 0. );
|
|---|
| 131 | }
|
|---|
| 132 | };
|
|---|
| 133 |
|
|---|
| 134 | #endif
|
|---|