1 # -*- coding: iso-8859-1 -*-
4 from hoomd_script
import *
8 # tests for variant types
9 class variant_tests (unittest
.TestCase
):
12 init
.create_random(N
=100, phi_p
=0.05);
14 sorter
.set_params(grid
=8)
16 # tests creation of the constant variant
18 v
= variant
._constant
(5)
19 self
.assertEqual(5.0, v
.cpp_variant
.getValue(0))
20 self
.assertEqual(5.0, v
.cpp_variant
.getValue(100000))
21 self
.assertEqual(5.0, v
.cpp_variant
.getValue(5000))
22 self
.assertEqual(5.0, v
.cpp_variant
.getValue(40))
23 self
.assertEqual(5.0, v
.cpp_variant
.getValue(50))
25 # tests a simple linear variant
26 def test_linear_interp(self
):
27 v
= variant
.linear_interp(points
= [(0, 10), (100, 20)]);
28 self
.assertEqual(15.0, v
.cpp_variant
.getValue(50));
29 self
.assertEqual(10.0, v
.cpp_variant
.getValue(0));
30 self
.assertEqual(20.0, v
.cpp_variant
.getValue(100));
31 self
.assertEqual(20.0, v
.cpp_variant
.getValue(1000));
33 # test the zero option on linear_interp
34 def test_linear_interp(self
):
37 v
= variant
.linear_interp(points
= [(0, 10), (100, 20)], zero
='now');
38 self
.assertEqual(15.0, v
.cpp_variant
.getValue(1050));
39 self
.assertEqual(10.0, v
.cpp_variant
.getValue(1000));
40 self
.assertEqual(20.0, v
.cpp_variant
.getValue(1100));
41 self
.assertEqual(20.0, v
.cpp_variant
.getValue(2000));
43 v2
= variant
.linear_interp(points
= [(0, 10), (100, 20)], zero
=500);
44 self
.assertEqual(15.0, v2
.cpp_variant
.getValue(550));
45 self
.assertEqual(10.0, v2
.cpp_variant
.getValue(500));
46 self
.assertEqual(20.0, v2
.cpp_variant
.getValue(600));
47 self
.assertEqual(20.0, v2
.cpp_variant
.getValue(1500));
49 # test the setup helper
50 def setup_variant_input_test(self
):
51 v
= variant
._setup
_variant
_input
(55);
52 self
.assertEqual(55.0, v
.cpp_variant
.getValue(0));
54 v
= variant
._setup
_variant
_input
(variant
.linear_interp(points
= [(0, 10), (100, 20)]));
55 self
.assertEqual(15.0, v
.cpp_variant
.getValue(50));
60 if __name__
== '__main__':
61 unittest
.main(argv
= ['test.py', '-v'])