2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 //! Name the unit test module
51 #define BOOST_TEST_MODULE vec2
52 #include "boost_utf_configure.h"
58 #include <boost/bind.hpp>
59 #include <boost/python.hpp>
60 #include <boost/function.hpp>
61 #include <boost/shared_ptr.hpp>
63 #include "VectorMath.h"
65 BOOST_AUTO_TEST_CASE( construction
)
67 // test each constructor separately
69 MY_BOOST_CHECK_SMALL(a
.x
, tol_small
);
70 MY_BOOST_CHECK_SMALL(a
.y
, tol_small
);
72 vec2
<Scalar
> b(123, 86);
73 MY_BOOST_CHECK_CLOSE(b
.x
, 123, tol
);
74 MY_BOOST_CHECK_CLOSE(b
.y
, 86, tol
);
77 BOOST_AUTO_TEST_CASE( component_wise
)
83 // test each component-wise operator separately
85 MY_BOOST_CHECK_CLOSE(c
.x
, 5, tol
);
86 MY_BOOST_CHECK_CLOSE(c
.y
, 8, tol
);
89 MY_BOOST_CHECK_CLOSE(c
.x
, -3, tol
);
90 MY_BOOST_CHECK_CLOSE(c
.y
, -4, tol
);
93 MY_BOOST_CHECK_CLOSE(c
.x
, 4, tol
);
94 MY_BOOST_CHECK_CLOSE(c
.y
, 12, tol
);
97 MY_BOOST_CHECK_CLOSE(c
.x
, 1.0/4.0, tol
);
98 MY_BOOST_CHECK_CLOSE(c
.y
, 2.0/6.0, tol
);
101 MY_BOOST_CHECK_CLOSE(c
.x
, -1, tol
);
102 MY_BOOST_CHECK_CLOSE(c
.y
, -2, tol
);
105 BOOST_AUTO_TEST_CASE( assignment_component_wise
)
111 // test each component-wise operator separately
113 MY_BOOST_CHECK_CLOSE(c
.x
, 5, tol
);
114 MY_BOOST_CHECK_CLOSE(c
.y
, 8, tol
);
115 MY_BOOST_CHECK_CLOSE(a
.x
, 5, tol
);
116 MY_BOOST_CHECK_CLOSE(a
.y
, 8, tol
);
118 a
= vec2
<Scalar
>(1,2);
120 MY_BOOST_CHECK_CLOSE(c
.x
, -3, tol
);
121 MY_BOOST_CHECK_CLOSE(c
.y
, -4, tol
);
122 MY_BOOST_CHECK_CLOSE(a
.x
, -3, tol
);
123 MY_BOOST_CHECK_CLOSE(a
.y
, -4, tol
);
125 a
= vec2
<Scalar
>(1,2);
127 MY_BOOST_CHECK_CLOSE(c
.x
, 4, tol
);
128 MY_BOOST_CHECK_CLOSE(c
.y
, 12, tol
);
129 MY_BOOST_CHECK_CLOSE(a
.x
, 4, tol
);
130 MY_BOOST_CHECK_CLOSE(a
.y
, 12, tol
);
132 a
= vec2
<Scalar
>(1,2);
134 MY_BOOST_CHECK_CLOSE(c
.x
, 1.0/4.0, tol
);
135 MY_BOOST_CHECK_CLOSE(c
.y
, 2.0/6.0, tol
);
136 MY_BOOST_CHECK_CLOSE(a
.x
, 1.0/4.0, tol
);
137 MY_BOOST_CHECK_CLOSE(a
.y
, 2.0/6.0, tol
);
140 BOOST_AUTO_TEST_CASE( scalar
)
146 // test each component-wise operator separately
148 MY_BOOST_CHECK_CLOSE(c
.x
, 4, tol
);
149 MY_BOOST_CHECK_CLOSE(c
.y
, 8, tol
);
152 MY_BOOST_CHECK_CLOSE(c
.x
, 4, tol
);
153 MY_BOOST_CHECK_CLOSE(c
.y
, 8, tol
);
156 MY_BOOST_CHECK_CLOSE(c
.x
, 1.0/4.0, tol
);
157 MY_BOOST_CHECK_CLOSE(c
.y
, 2.0/4.0, tol
);
160 BOOST_AUTO_TEST_CASE( assignment_scalar
)
165 // test each component-wise operator separately
166 a
= vec2
<Scalar
>(1,2);
168 MY_BOOST_CHECK_CLOSE(a
.x
, 4, tol
);
169 MY_BOOST_CHECK_CLOSE(a
.y
, 8, tol
);
171 a
= vec2
<Scalar
>(1,2);
173 MY_BOOST_CHECK_CLOSE(a
.x
, 1.0/4.0, tol
);
174 MY_BOOST_CHECK_CLOSE(a
.y
, 2.0/4.0, tol
);
177 BOOST_AUTO_TEST_CASE( vector_ops
)
184 // test each vector operation
186 MY_BOOST_CHECK_CLOSE(d
, 16, tol
);
189 MY_BOOST_CHECK_SMALL(dot(a
,c
), tol_small
);
192 BOOST_AUTO_TEST_CASE( comparison
)
194 vec2
<Scalar
> a(1.1,2.1);
196 vec2
<Scalar
> c(2.1,1.1);
200 BOOST_CHECK(!(a
==c
));
203 BOOST_CHECK(!(a
!=b
));
207 BOOST_AUTO_TEST_CASE( projection
)
209 vec2
<Scalar
> a(3.4,5.5);
210 vec2
<Scalar
> b(0.1,0);
215 MY_BOOST_CHECK_CLOSE(c
.x
, 3.4, tol
);
216 MY_BOOST_CHECK_SMALL(c
.y
, tol_small
);
219 BOOST_AUTO_TEST_CASE( perpdot_product
)
221 vec2
<Scalar
> a(3.4,5.5);
222 vec2
<Scalar
> b(0.1,-4.2);
225 Scalar c
= perpdot(a
,b
);
226 MY_BOOST_CHECK_CLOSE(c
, -14.83, tol
);
229 BOOST_AUTO_TEST_CASE( test_swap
)
231 vec2
<Scalar
> a(1.1, 2.2);
232 vec2
<Scalar
> b(3.3, 4.4);
233 vec2
<Scalar
> c(1.1, 2.2);
234 vec2
<Scalar
> d(3.3, 4.4);