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 | * CopyAtomsInterfaceUnitTest.cpp
|
---|
10 | *
|
---|
11 | * Created on: Mar 17, 2012
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "CopyAtomsInterfaceUnitTest.hpp"
|
---|
21 |
|
---|
22 | #include <cppunit/CompilerOutputter.h>
|
---|
23 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
24 | #include <cppunit/ui/text/TestRunner.h>
|
---|
25 | #include <iostream>
|
---|
26 |
|
---|
27 | #include "CodePatterns/Log.hpp"
|
---|
28 |
|
---|
29 | #include "Atom/atom.hpp"
|
---|
30 | #include "Atom/CopyAtoms/CopyAtomsInterface.hpp"
|
---|
31 | #include "Atom/CopyAtoms/CopyAtoms_Simple.hpp"
|
---|
32 | #include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
|
---|
33 | #include "Bond/bond.hpp"
|
---|
34 | #include "World.hpp"
|
---|
35 |
|
---|
36 | #ifdef HAVE_TESTRUNNER
|
---|
37 | #include "UnitTestMain.hpp"
|
---|
38 | #endif /*HAVE_TESTRUNNER*/
|
---|
39 |
|
---|
40 | /********************************************** Test classes **************************************/
|
---|
41 | // Registers the fixture into the 'registry'
|
---|
42 | CPPUNIT_TEST_SUITE_REGISTRATION( CopyAtomsInterfaceTest );
|
---|
43 |
|
---|
44 | // set up and tear down
|
---|
45 | void CopyAtomsInterfaceTest::setUp()
|
---|
46 | {
|
---|
47 | setVerbosity(5);
|
---|
48 |
|
---|
49 | for(int i=0;i<ATOM_COUNT;++i){
|
---|
50 | atoms[i]= World::getInstance().createAtom();
|
---|
51 | atomIds[i]= atoms[i]->getId();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | void CopyAtomsInterfaceTest::tearDown()
|
---|
56 | {
|
---|
57 | World::purgeInstance();
|
---|
58 | }
|
---|
59 |
|
---|
60 | /** Unit test on whether CopyAtomsInterface::operator() works as expected.
|
---|
61 | *
|
---|
62 | */
|
---|
63 | void CopyAtomsInterfaceTest::CopyAtomsInterfaceOperatorTest()
|
---|
64 | {
|
---|
65 | CopyAtomsInterface copyMethod;
|
---|
66 | CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
|
---|
67 |
|
---|
68 | copyMethod(atomVec);
|
---|
69 |
|
---|
70 | CPPUNIT_ASSERT_EQUAL( (size_t)2, World::getInstance().getAllAtoms().size() );
|
---|
71 | CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
|
---|
72 | CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
|
---|
73 | CPPUNIT_ASSERT_EQUAL( (atom *) NULL, copyMethod.CopiedAtoms[0] );
|
---|
74 | }
|
---|
75 |
|
---|
76 | /** Unit test on whether CopyAtoms_Simple::operator() works as expected.
|
---|
77 | *
|
---|
78 | */
|
---|
79 | void CopyAtomsInterfaceTest::CopyAtoms_SimpleOperatorTest()
|
---|
80 | {
|
---|
81 | CopyAtoms_Simple copyMethod;
|
---|
82 | CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
|
---|
83 |
|
---|
84 | copyMethod(atomVec);
|
---|
85 |
|
---|
86 | CPPUNIT_ASSERT_EQUAL( (size_t)4, World::getInstance().getAllAtoms().size() );
|
---|
87 | CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
|
---|
88 | CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
|
---|
89 | CPPUNIT_ASSERT( copyMethod.CopiedAtoms[0] != NULL );
|
---|
90 | }
|
---|
91 |
|
---|
92 | /** Unit test on whether CopyAtoms_withBonds::operator() works as expected.
|
---|
93 | *
|
---|
94 | */
|
---|
95 | void CopyAtomsInterfaceTest::CopyAtoms_withBondsOperatorTest()
|
---|
96 | {
|
---|
97 | CopyAtoms_withBonds copyMethod;
|
---|
98 | {
|
---|
99 | CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
|
---|
100 | CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
|
---|
101 |
|
---|
102 | copyMethod(atomVec);
|
---|
103 |
|
---|
104 | CPPUNIT_ASSERT_EQUAL( (size_t)4, World::getInstance().getAllAtoms().size() );
|
---|
105 | CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
|
---|
106 | CPPUNIT_ASSERT( copyMethod.CopiedAtoms[0] != NULL );
|
---|
107 | CPPUNIT_ASSERT( copyMethod.CopiedAtoms[1] != NULL );
|
---|
108 | CPPUNIT_ASSERT_EQUAL( copyMethod.CopiedAtoms, copyMethod.getCopiedAtoms() );
|
---|
109 | }
|
---|
110 |
|
---|
111 | // create bonds
|
---|
112 | {
|
---|
113 | atoms[0]->addBond( (size_t)0, atoms[1]);
|
---|
114 | const BondList & ListOfBonds = atoms[0]->getListOfBonds();
|
---|
115 | CPPUNIT_ASSERT( !ListOfBonds.empty() );
|
---|
116 | const bond * const _bond = *ListOfBonds.begin();
|
---|
117 | CPPUNIT_ASSERT( _bond->GetOtherAtom(atoms[0]) == atoms[1] );
|
---|
118 | }
|
---|
119 | {
|
---|
120 | CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
|
---|
121 | CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
|
---|
122 |
|
---|
123 | copyMethod(atomVec);
|
---|
124 |
|
---|
125 | CPPUNIT_ASSERT_EQUAL( (size_t)6, World::getInstance().getAllAtoms().size() );
|
---|
126 | CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
|
---|
127 | CPPUNIT_ASSERT( copyMethod.CopiedAtoms[0] != NULL );
|
---|
128 | CPPUNIT_ASSERT( copyMethod.CopiedAtoms[1] != NULL );
|
---|
129 | const BondList & ListOfBonds = copyMethod.CopiedAtoms[0]->getListOfBonds();
|
---|
130 | CPPUNIT_ASSERT( !ListOfBonds.empty() );
|
---|
131 | const bond * const _bond = *ListOfBonds.begin();
|
---|
132 | CPPUNIT_ASSERT( _bond->GetOtherAtom(copyMethod.CopiedAtoms[0]) == copyMethod.CopiedAtoms[1] );
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|