1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * MoleculeUnitTest.cpp
|
---|
10 | *
|
---|
11 | * Created on: Mar 19, 2012
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include <cppunit/CompilerOutputter.h>
|
---|
21 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
22 | #include <cppunit/ui/text/TestRunner.h>
|
---|
23 |
|
---|
24 | #include <algorithm>
|
---|
25 |
|
---|
26 | #include "Atom/atom.hpp"
|
---|
27 | #include "CodePatterns/Assert.hpp"
|
---|
28 | #include "Element/element.hpp"
|
---|
29 | #include "Element/periodentafel.hpp"
|
---|
30 | #include "molecule.hpp"
|
---|
31 |
|
---|
32 | #include "MoleculeUnitTest.hpp"
|
---|
33 |
|
---|
34 |
|
---|
35 | #ifdef HAVE_TESTRUNNER
|
---|
36 | #include "UnitTestMain.hpp"
|
---|
37 | #endif /*HAVE_TESTRUNNER*/
|
---|
38 |
|
---|
39 | /********************************************** Test classes **************************************/
|
---|
40 |
|
---|
41 | // Registers the fixture into the 'registry'
|
---|
42 | CPPUNIT_TEST_SUITE_REGISTRATION( MoleculeUnittest );
|
---|
43 |
|
---|
44 | size_t MoleculeUnittest::MaxAtoms = 6;
|
---|
45 |
|
---|
46 | void MoleculeUnittest::setUp(){
|
---|
47 | // failing asserts should be thrown
|
---|
48 | ASSERT_DO(Assert::Throw);
|
---|
49 |
|
---|
50 | atomVector.resize((size_t)MaxAtoms);
|
---|
51 | std::generate_n(atomVector.begin(), MaxAtoms,
|
---|
52 | boost::bind(&World::createAtom, boost::ref(World::getInstance())));
|
---|
53 | std::for_each(atomVector.begin(), atomVector.end(),
|
---|
54 | boost::bind(static_cast<void (AtomInfo::*)(int)>(&AtomInfo::setType), _1, (atomicNumber_t)1));
|
---|
55 |
|
---|
56 | mol = new molecule;
|
---|
57 | std::for_each(atomVector.begin(), atomVector.end(),
|
---|
58 | boost::bind(&molecule::AddAtom, boost::ref(mol), _1));
|
---|
59 | }
|
---|
60 |
|
---|
61 | void MoleculeUnittest::tearDown()
|
---|
62 | {
|
---|
63 | delete mol;
|
---|
64 | World::purgeInstance();
|
---|
65 | }
|
---|
66 |
|
---|
67 | /** Unit test for molecule::getBoundingShape() with a linear chain
|
---|
68 | *
|
---|
69 | */
|
---|
70 | void MoleculeUnittest::getBoundingShapeTest_linearchain()
|
---|
71 | {
|
---|
72 | // prepare a chain of atoms
|
---|
73 | double offset = 0.;
|
---|
74 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
75 | _atom->setPosition( Vector(offset, 0., 0.) );
|
---|
76 | offset += 1.;
|
---|
77 | }
|
---|
78 |
|
---|
79 | {
|
---|
80 | // get bounding shape
|
---|
81 | Shape s = mol->getBoundingShape();
|
---|
82 |
|
---|
83 | // check that each atom is truely inside the shape
|
---|
84 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
85 | CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | /** Unit test for molecule::getBoundingShape() with a v-shaped molecule.
|
---|
91 | *
|
---|
92 | */
|
---|
93 | void MoleculeUnittest::getBoundingShapeTest_vshaped()
|
---|
94 | {
|
---|
95 | double xoffset = -2.5;
|
---|
96 | double yoffset = -2.5;
|
---|
97 | double yadder = -1;
|
---|
98 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
99 | _atom->setPosition( Vector(xoffset, yoffset, 0.) );
|
---|
100 | xoffset += 1.;
|
---|
101 | yoffset -= yadder;
|
---|
102 | if (yoffset <= 0) {
|
---|
103 | yadder = 1.;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | {
|
---|
108 | // get bounding shape
|
---|
109 | Shape s = mol->getBoundingShape();
|
---|
110 |
|
---|
111 | // check that each atom is truely inside the shape
|
---|
112 | BOOST_FOREACH(atom *_atom, atomVector) {
|
---|
113 | CPPUNIT_ASSERT( s.isInside(_atom->getPosition()) );
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|