Enable parallel tests.
[hoomd-blue.git] / test / hoomd_script / test_group.py
blobee18606e9a67e3e0038af5c69cc9277944a2c075
1 # -*- coding: iso-8859-1 -*-
2 # Maintainer: joaander
4 from hoomd_script import *
5 import unittest
6 import os
7 import gc
9 # group - test grouping commands
10 class pair_group_tests (unittest.TestCase):
11 def setUp(self):
12 print("setUp");
13 print
14 sysdef = init.create_empty(N=11, box=data.boxdim(L=5), particle_types=['A', 'B']);
15 sysdef.particles[0].position = (0,0,0);
16 sysdef.particles[0].type = 'A';
17 sysdef.particles[1].position = (1,1,1);
18 sysdef.particles[1].type = 'B';
19 sysdef.particles[2].position = (1,1,1);
20 sysdef.particles[2].type = 'B';
21 sysdef.particles[3].position = (-1,-1,-1);
22 sysdef.particles[3].type = 'A';
23 sysdef.particles[4].position = (-1,-1,-1);
24 sysdef.particles[4].type = 'A';
25 sysdef.particles[5].position = (2,0,0);
26 sysdef.particles[5].type = 'B';
27 sysdef.particles[6].position = (0,2,0);
28 sysdef.particles[6].type = 'A';
29 sysdef.particles[7].position = (0,0,2);
30 sysdef.particles[7].type = 'A';
31 sysdef.particles[8].position = (-2,0,0);
32 sysdef.particles[8].type = 'B';
33 sysdef.particles[9].position = (0,-2,0);
34 sysdef.particles[9].type = 'B';
35 sysdef.particles[10].position = (0,0,-2);
36 sysdef.particles[10].type = 'B';
38 sorter.set_params(grid=8)
40 def test_all(self):
41 all = group.all()
42 tags = [(x.tag) for x in all]
43 self.assertEqual(tags, list(range(11)))
45 def test_tags(self):
46 one = group.tags(5)
47 tags = [(x.tag) for x in one]
48 self.assertEqual(tags, [5])
50 part = group.tags(tag_min=5, tag_max=8)
51 tags = [(x.tag) for x in part]
52 self.assertEqual(tags, list(range(5,9)))
54 def test_type(self):
55 A = group.type(type='A')
56 tags = [(x.tag) for x in A]
57 self.assertEqual(tags, [0, 3, 4, 6, 7])
59 B = group.type(type='B')
60 tags = [(x.tag) for x in B]
61 self.assertEqual(tags, [1, 2, 5, 8, 9, 10])
63 def test_cuboid_xmin(self):
64 g = group.cuboid(name='test', xmin=None)
65 tags = [(x.tag) for x in g]
66 self.assertEqual(tags, list(range(11)))
68 g = group.cuboid(name='test', xmin=0.99)
69 tags = [(x.tag) for x in g]
70 self.assertEqual(tags, [1,2,5])
72 def test_cuboid_xmax(self):
73 g = group.cuboid(name='test', xmax=None)
74 tags = [(x.tag) for x in g]
75 self.assertEqual(tags, list(range(11)))
77 g = group.cuboid(name='test', xmax=-0.99)
78 tags = [(x.tag) for x in g]
79 self.assertEqual(tags, [3,4,8])
81 def test_cuboid_ymin(self):
82 g = group.cuboid(name='test', ymin=None)
83 tags = [(x.tag) for x in g]
84 self.assertEqual(tags, list(range(11)))
86 g = group.cuboid(name='test', ymin=0.99)
87 tags = [(x.tag) for x in g]
88 self.assertEqual(tags, [1,2,6])
90 def test_cuboid_ymax(self):
91 g = group.cuboid(name='test', ymax=None)
92 tags = [(x.tag) for x in g]
93 self.assertEqual(tags, list(range(11)))
95 g = group.cuboid(name='test', ymax=-0.99)
96 tags = [(x.tag) for x in g]
97 self.assertEqual(tags, [3,4,9])
99 def test_cuboid_zmin(self):
100 g = group.cuboid(name='test', zmin=None)
101 tags = [(x.tag) for x in g]
102 self.assertEqual(tags, list(range(11)))
104 g = group.cuboid(name='test', zmin=0.99)
105 tags = [(x.tag) for x in g]
106 self.assertEqual(tags, [1,2,7])
108 def test_cuboid_zmax(self):
109 g = group.cuboid(name='test', zmax=None)
110 tags = [(x.tag) for x in g]
111 self.assertEqual(tags, list(range(11)))
113 g = group.cuboid(name='test', zmax=-0.99)
114 tags = [(x.tag) for x in g]
115 self.assertEqual(tags, [3,4,10])
117 def test_tag_list(self):
118 g = group.tag_list(name='a', tags=[0, 5, 9]);
119 tags = [(x.tag) for x in g]
120 self.assertEqual(tags, [0,5,9])
122 def test_union(self):
123 A = group.type(type='A')
124 B = group.type(type='B')
126 union = group.union(name='test', a=A,b=B)
127 tags = [(x.tag) for x in union]
128 self.assertEqual(tags, list(range(11)))
130 def test_intersection(self):
131 A = group.type(type='A')
132 B = group.type(type='B')
133 all = group.all();
135 isectAB = group.intersection(name='test', a=A,b=B)
136 tags = [(x.tag) for x in isectAB]
137 self.assertEqual(tags, [])
139 isectAall = group.intersection(name='test', a=A,b=all)
140 tags = [(x.tag) for x in isectAall]
141 self.assertEqual(tags, [0, 3, 4, 6, 7])
143 def test_difference(self):
144 B = group.type(type='B')
145 all = group.all();
147 diffBall = group.difference(name='test', a=all,b=B)
148 tags = [(x.tag) for x in diffBall]
149 self.assertEqual(tags, [0, 3, 4, 6, 7])
151 def tearDown(self):
152 init.reset();
155 if __name__ == '__main__':
156 unittest.main(argv = ['test.py', '-v'])