1 # -*- coding: iso-8859-1 -*-
4 from hoomd_script
import *
8 # unit tests for init.create_random_polymers
9 class init_create_random_polymer_tests (unittest
.TestCase
):
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
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
,
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
,
39 separation
=self
.separation
);
40 self
.assertRaises(RuntimeError,
41 init
.create_random_polymers
,
43 polymers
=self
.polymer1
,
44 separation
=self
.separation
);
45 self
.assertRaises(RuntimeError,
46 init
.create_random_polymers
,
49 separation
=self
.separation
);
50 self
.assertRaises(RuntimeError,
51 init
.create_random_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
,
63 polymers
=[bad_polymer1
],
64 separation
=self
.separation
);
65 self
.assertRaises(RuntimeError,
66 init
.create_random_polymers
,
68 polymers
=[bad_polymer2
],
69 separation
=self
.separation
);
70 self
.assertRaises(RuntimeError,
71 init
.create_random_polymers
,
73 polymers
=[bad_polymer3
],
74 separation
=self
.separation
);
75 self
.assertRaises(RuntimeError,
76 init
.create_random_polymers
,
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
,
88 polymers
=self
.polymers
,
89 separation
=bad_separation1
);
90 self
.assertRaises(RuntimeError,
91 init
.create_random_polymers
,
93 polymers
=self
.polymers
,
94 separation
=bad_separation2
);
95 self
.assertRaises(RuntimeError,
96 init
.create_random_polymers
,
98 polymers
=self
.polymers
,
99 separation
=bad_separation3
);
105 if __name__
== '__main__':
106 unittest
.main(argv
= ['test.py', '-v'])