Enable parallel tests.
[hoomd-blue.git] / test / hoomd_script / test_init_create_random_polymers.py
blob3d946d31cb46aaedf80ace3307cfbac48a6697d1
1 # -*- coding: iso-8859-1 -*-
2 # Maintainer: joaander
4 from hoomd_script import *
5 import unittest
6 import os
8 # unit tests for init.create_random_polymers
9 class init_create_random_polymer_tests (unittest.TestCase):
10 def setUp(self):
11 print
12 self.polymer1 = dict(bond_len=1.2, type=['A']*6 + ['B']*7 + ['A']*6, bond="linear", count=100);
13 self.polymer2 = dict(bond_len=1.2, type=['B']*4, bond="linear", count=10)
14 self.polymers = [self.polymer1, self.polymer2]
15 self.box = data.boxdim(L=35);
16 self.separation=dict(A=0.35, B=0.35)
18 # tests basic creation of the random initializer
19 def test(self):
20 init.create_random_polymers(box=self.box, polymers=self.polymers, separation=self.separation);
21 self.assert_(globals.system_definition);
22 self.assert_(globals.system);
24 # checks for an error if initialized twice
25 def test_create_random_inittwice(self):
26 init.create_random_polymers(box=self.box, polymers=self.polymers, separation=self.separation);
27 self.assertRaises(RuntimeError,
28 init.create_random_polymers,
29 box=self.box,
30 polymers=self.polymers,
31 separation=self.separation);
33 # checks that invalid arguments are detected
34 def test_bad_polymers(self):
35 self.assertRaises(RuntimeError,
36 init.create_random_polymers,
37 box=self.box,
38 polymers=[],
39 separation=self.separation);
40 self.assertRaises(RuntimeError,
41 init.create_random_polymers,
42 box=self.box,
43 polymers=self.polymer1,
44 separation=self.separation);
45 self.assertRaises(RuntimeError,
46 init.create_random_polymers,
47 box=self.box,
48 polymers=5,
49 separation=self.separation);
50 self.assertRaises(RuntimeError,
51 init.create_random_polymers,
52 box=self.box,
53 polymers="polymers",
54 separation=self.separation);
56 bad_polymer1 = dict(bond_len=1.2, bond="linear", count=10)
57 bad_polymer2 = dict(type=['B']*4, bond="linear", count=10)
58 bad_polymer3 = dict(bond_len=1.2, type=['B']*4, count=10)
59 bad_polymer4 = dict(bond_len=1.2, type=['B']*4, bond="linear")
60 self.assertRaises(RuntimeError,
61 init.create_random_polymers,
62 box=self.box,
63 polymers=[bad_polymer1],
64 separation=self.separation);
65 self.assertRaises(RuntimeError,
66 init.create_random_polymers,
67 box=self.box,
68 polymers=[bad_polymer2],
69 separation=self.separation);
70 self.assertRaises(RuntimeError,
71 init.create_random_polymers,
72 box=self.box,
73 polymers=[bad_polymer3],
74 separation=self.separation);
75 self.assertRaises(RuntimeError,
76 init.create_random_polymers,
77 box=self.box,
78 polymers=[bad_polymer4],
79 separation=self.separation);
81 def test_bad_separation(self):
82 bad_separation1 = dict(A=0.35)
83 bad_separation2 = dict(B=0.35)
84 bad_separation3 = dict(C=0.35)
85 self.assertRaises(RuntimeError,
86 init.create_random_polymers,
87 box=self.box,
88 polymers=self.polymers,
89 separation=bad_separation1);
90 self.assertRaises(RuntimeError,
91 init.create_random_polymers,
92 box=self.box,
93 polymers=self.polymers,
94 separation=bad_separation2);
95 self.assertRaises(RuntimeError,
96 init.create_random_polymers,
97 box=self.box,
98 polymers=self.polymers,
99 separation=bad_separation3);
101 def tearDown(self):
102 init.reset();
105 if __name__ == '__main__':
106 unittest.main(argv = ['test.py', '-v'])