1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010-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 | * ShapeOpsUnitTest.cpp
|
---|
10 | *
|
---|
11 | * Created on: Jun 18, 2010
|
---|
12 | * Author: crueger
|
---|
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 <cmath>
|
---|
25 |
|
---|
26 | #ifdef HAVE_TESTRUNNER
|
---|
27 | #include "UnitTestMain.hpp"
|
---|
28 | #endif /*HAVE_TESTRUNNER*/
|
---|
29 |
|
---|
30 | #include "CodePatterns/Assert.hpp"
|
---|
31 |
|
---|
32 | #include "Helpers/defs.hpp"
|
---|
33 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
|
---|
34 | #include "LinearAlgebra/Vector.hpp"
|
---|
35 | #include "Shapes/BaseShapes.hpp"
|
---|
36 | #include "Shapes/Shape.hpp"
|
---|
37 | #include "Shapes/ShapeOps.hpp"
|
---|
38 |
|
---|
39 | #include "ShapeOpsUnitTest.hpp"
|
---|
40 |
|
---|
41 | // Registers the fixture into the 'registry'
|
---|
42 | CPPUNIT_TEST_SUITE_REGISTRATION( ShapeOpsTest );
|
---|
43 |
|
---|
44 | void ShapeOpsTest::setUp()
|
---|
45 | {
|
---|
46 | // failing asserts should be thrown
|
---|
47 | ASSERT_DO(Assert::Throw);
|
---|
48 | }
|
---|
49 |
|
---|
50 | void ShapeOpsTest::tearDown()
|
---|
51 | {}
|
---|
52 |
|
---|
53 | void ShapeOpsTest::resizeTest()
|
---|
54 | {
|
---|
55 | Shape s = resize(Sphere(), 2.);
|
---|
56 |
|
---|
57 | CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
|
---|
58 | CPPUNIT_ASSERT( s.isInside( Vector(0.,1.5,0.) ) );
|
---|
59 | CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,1.5) ) );
|
---|
60 | CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
|
---|
61 | CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,2.,0.) ) );
|
---|
62 | CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,2.) ) );
|
---|
63 | }
|
---|
64 |
|
---|
65 | void ShapeOpsTest::translateTest()
|
---|
66 | {
|
---|
67 | Shape s = translate(Sphere(), Vector(1.,0.,0.));
|
---|
68 |
|
---|
69 | CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
|
---|
70 | CPPUNIT_ASSERT( s.isInside( Vector(1.,.5,0.) ) );
|
---|
71 | CPPUNIT_ASSERT( s.isInside( Vector(1.,0.,.5) ) );
|
---|
72 | CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
|
---|
73 | CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,1.,0.) ) );
|
---|
74 | CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,1.) ) );
|
---|
75 | CPPUNIT_ASSERT( !s.isInside( Vector(-.5,0.,0.) ) );
|
---|
76 | CPPUNIT_ASSERT( !s.isInside( Vector(0.,-.5,0.) ) );
|
---|
77 | CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,-.5) ) );
|
---|
78 | }
|
---|
79 |
|
---|
80 | void ShapeOpsTest::stretchTest()
|
---|
81 | {
|
---|
82 | #ifndef NDEBUG
|
---|
83 | CPPUNIT_ASSERT_THROW( Shape test = stretch(Sphere(), Vector(-2.,0.,0.)), Assert::AssertionFailure );
|
---|
84 | #endif
|
---|
85 | Shape s = stretch(Sphere(), Vector(2.,1.,1.));
|
---|
86 |
|
---|
87 | CPPUNIT_ASSERT( s.isInside( Vector(1.5,0.,0.) ) );
|
---|
88 | CPPUNIT_ASSERT( !s.isInside( Vector(0.,1.5,0.) ) );
|
---|
89 | CPPUNIT_ASSERT( !s.isInside( Vector(0.,0.,1.5) ) );
|
---|
90 | CPPUNIT_ASSERT( s.isOnSurface( Vector(2.,0.,0.) ) );
|
---|
91 | CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
|
---|
92 | CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
|
---|
93 | }
|
---|
94 |
|
---|
95 | void ShapeOpsTest::transformTest()
|
---|
96 | {
|
---|
97 | RealSpaceMatrix M;
|
---|
98 | M.setRotation(45., 0., 0.);
|
---|
99 | Shape s = transform(Sphere(), M);
|
---|
100 |
|
---|
101 | CPPUNIT_ASSERT( s.isInside( Vector(.5,0.,0.) ) );
|
---|
102 | CPPUNIT_ASSERT( s.isInside( Vector(0.,.5,0.) ) );
|
---|
103 | CPPUNIT_ASSERT( s.isInside( Vector(0.,0.,.5) ) );
|
---|
104 | CPPUNIT_ASSERT( s.isOnSurface( Vector(1.,0.,0.) ) );
|
---|
105 | CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,1.,0.) ) );
|
---|
106 | CPPUNIT_ASSERT( s.isOnSurface( Vector(0.,0.,1.) ) );
|
---|
107 | }
|
---|
108 |
|
---|