Enable parallel tests.
[hoomd-blue.git] / test / hoomd_script / test_variant.py
blob123cea1c7e0ece02f5ee2e304ff7ef3ccb644965
1 # -*- coding: iso-8859-1 -*-
2 # Maintainer: joaander
4 from hoomd_script import *
5 import unittest
6 import os
8 # tests for variant types
9 class variant_tests (unittest.TestCase):
10 def setUp(self):
11 print
12 init.create_random(N=100, phi_p=0.05);
14 sorter.set_params(grid=8)
16 # tests creation of the constant variant
17 def test_const(self):
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):
35 run(1000)
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));
57 def tearDown(self):
58 init.reset();
60 if __name__ == '__main__':
61 unittest.main(argv = ['test.py', '-v'])