[e23075] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[6d608d] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[e23075] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * VectorSetUnitTest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Jan 06, 2012
|
---|
| 12 | * Author: heber
|
---|
| 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 "VectorSetUnitTest.hpp"
|
---|
| 27 |
|
---|
[f6ad4d] | 28 | #include "RealSpaceMatrix.hpp"
|
---|
| 29 | #include "VectorSet.hpp"
|
---|
| 30 |
|
---|
[e23075] | 31 | #ifdef HAVE_TESTRUNNER
|
---|
| 32 | #include "UnitTestMain.hpp"
|
---|
| 33 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 34 |
|
---|
| 35 | #include <iostream>
|
---|
| 36 |
|
---|
| 37 | /********************************************** Test classes **************************************/
|
---|
| 38 |
|
---|
| 39 | // Registers the fixture into the 'registry'
|
---|
| 40 | CPPUNIT_TEST_SUITE_REGISTRATION( VectorSetTest );
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | void VectorSetTest::setUp()
|
---|
| 44 | {
|
---|
| 45 | list.push_back(Vector(0.,0.,0.));
|
---|
| 46 | list.push_back(Vector(1.,0.,0.));
|
---|
| 47 | list.push_back(Vector(0.,1.,0.));
|
---|
| 48 | list.push_back(Vector(0.,1.,1.));
|
---|
| 49 | list.push_back(Vector(2.,1.,0.));
|
---|
| 50 | list.push_back(Vector(1.,2.,3.));
|
---|
| 51 |
|
---|
| 52 | CPPUNIT_ASSERT_EQUAL( (size_t)6, list.size() );
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | void VectorSetTest::tearDown()
|
---|
| 57 | {
|
---|
| 58 | list.clear();
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[f6ad4d] | 61 | /** UnitTest for Cstor(Set &)
|
---|
| 62 | */
|
---|
| 63 | void VectorSetTest::copyConstructorTest()
|
---|
| 64 | {
|
---|
| 65 | VECTORSET(std::vector) worklist(list);
|
---|
| 66 | CPPUNIT_ASSERT_EQUAL( list.size(), worklist.size() );
|
---|
| 67 | std::vector<Vector>::const_iterator iter = list.begin();
|
---|
| 68 | VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
|
---|
| 69 | for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
|
---|
| 70 | CPPUNIT_ASSERT( ((*iter)) == (*workiter) );
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 |
|
---|
[e23075] | 74 | /** UnitTest for translate()
|
---|
| 75 | */
|
---|
| 76 | void VectorSetTest::translateTest()
|
---|
| 77 | {
|
---|
| 78 | VECTORSET(std::vector) worklist(list);
|
---|
| 79 | Vector translater(1.,0.,0.);
|
---|
| 80 | worklist.translate(translater);
|
---|
| 81 | VECTORSET(std::vector)::const_iterator iter = list.begin();
|
---|
| 82 | VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
|
---|
| 83 | for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
|
---|
| 84 | CPPUNIT_ASSERT( ((*iter)+(translater)) == (*workiter) );
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[f6ad4d] | 87 | /** UnitTest for transform()
|
---|
| 88 | */
|
---|
| 89 | void VectorSetTest::transformTest()
|
---|
| 90 | {
|
---|
| 91 | VECTORSET(std::vector) worklist(list);
|
---|
| 92 | RealSpaceMatrix M;
|
---|
| 93 | M.setIdentity();
|
---|
| 94 | M *= 2.;
|
---|
| 95 | worklist.transform(M);
|
---|
| 96 | VECTORSET(std::vector)::const_iterator iter = list.begin();
|
---|
| 97 | VECTORSET(std::vector)::const_iterator workiter = worklist.begin();
|
---|
| 98 | for (;(iter != list.end()) && (workiter != worklist.end()); ++iter, ++workiter)
|
---|
| 99 | CPPUNIT_ASSERT( (2.*(*iter)) == (*workiter) );
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[e23075] | 102 | /** UnitTest for minDistance()
|
---|
| 103 | */
|
---|
| 104 | void VectorSetTest::minDistanceTest()
|
---|
| 105 | {
|
---|
[f6ad4d] | 106 | VECTORSET(std::vector) worklist(list);
|
---|
[e23075] | 107 | {
|
---|
| 108 | VECTORSET(std::vector) somelist;
|
---|
| 109 | for (double x=1.;x<6.;++x)
|
---|
| 110 | somelist.push_back(Vector(x,0.,0.));
|
---|
| 111 | Vector center(0.,0.,0.);
|
---|
| 112 | Vector mindist = somelist.minDistance(center);
|
---|
| 113 | CPPUNIT_ASSERT_EQUAL (Vector(1., 0., 0.), mindist);
|
---|
| 114 | }
|
---|
| 115 | {
|
---|
| 116 | Vector center(5.,0.,0.);
|
---|
[f6ad4d] | 117 | Vector mindist = worklist.minDistance(center);
|
---|
[e23075] | 118 | CPPUNIT_ASSERT_EQUAL (Vector(2., 1., 0.)-center, mindist);
|
---|
| 119 | }
|
---|
| 120 | {
|
---|
[f6ad4d] | 121 | for (VECTORSET(std::vector)::const_iterator iter = worklist.begin();
|
---|
| 122 | iter != worklist.end(); ++iter) {
|
---|
| 123 | Vector mindist = worklist.minDistance(*iter);
|
---|
[e23075] | 124 | CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0.), mindist );
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | /** UnitTest for minDistance()
|
---|
| 130 | */
|
---|
| 131 | void VectorSetTest::minDistSquaredTest()
|
---|
| 132 | {
|
---|
[f6ad4d] | 133 | VECTORSET(std::vector) worklist(list);
|
---|
[e23075] | 134 | {
|
---|
| 135 | Vector center(5.,0.,0.);
|
---|
[f6ad4d] | 136 | double mindist = worklist.minDistSquared(center);
|
---|
[e23075] | 137 | double check = Vector(2., 1., 0.).DistanceSquared(center);
|
---|
| 138 | CPPUNIT_ASSERT_EQUAL( check, mindist );
|
---|
| 139 | }
|
---|
| 140 | {
|
---|
[f6ad4d] | 141 | for (VECTORSET(std::vector)::const_iterator iter = worklist.begin();
|
---|
| 142 | iter != worklist.end(); ++iter) {
|
---|
| 143 | double mindist = worklist.minDistSquared(*iter);
|
---|
[e23075] | 144 | CPPUNIT_ASSERT_EQUAL( 0., mindist );
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | }
|
---|