source: inundation-numpy-branch/pyvolution/test_quad.py @ 3330

Last change on this file since 3330 was 2608, checked in by ole, 19 years ago

Played with custom exceptions for ANUGA

File size: 3.8 KB
Line 
1import unittest
2from quad import Cell, build_quadtree
3
4from general_mesh import General_mesh as Mesh
5
6import types, sys
7
8#-------------------------------------------------------------
9
10class Test_Quad(unittest.TestCase):
11
12    def setUp(self):
13        self.cell = Cell(100, 140, 0, 40, 'cell')
14
15        a = [3, 107]
16        b = [5, 107]
17        c = [5, 105]
18        d = [7, 107]
19        e = [15, 115]
20        f = [15, 130]
21        g = [30, 110]
22        h = [30, 130]
23
24        points = [a, b, c, d, e, f, g, h]
25        #bac, bce, ecf, dbe, daf, dae
26        vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]]
27
28        mesh = Mesh(points, vertices)
29        self.mesh = mesh
30        Cell.initialise(mesh)
31
32    def tearDown(self):
33        pass
34
35    def test_add_points_2_cell(self):
36        self.cell.insert(0)
37        self.cell.insert(1)
38
39        result = self.cell.retrieve()
40        assert type(result) in [types.ListType,types.TupleType],\
41                                'should be a list'
42        self.assertEqual(len(result),2)
43
44    def test_add_points_2_cellII(self):
45        self.cell.insert([0,1,2,3,4,5,6,7])
46
47        result = self.cell.retrieve()
48        assert type(result) in [types.ListType,types.TupleType],\
49                                'should be a list'
50        self.assertEqual(len(result),8)
51
52
53    def test_search(self):
54        self.cell.insert([0,1,2,3,4,5,6,7])
55        self.cell.split(4)
56
57        result =  self.cell.search(x = 1, y = 101)
58        assert type(result) in [types.ListType,types.TupleType],\
59                                'should be a list'
60        self.assertEqual(result, [0,1,2,3])
61
62
63    def test_clear_1(self):
64        self.cell.insert([0,1,2,3,4,5,6,7])
65        assert self.cell.count() == 8
66        self.cell.clear()
67
68        #This one actually revealed a bug :-)
69        assert self.cell.count() == 0
70
71    def test_clear_2(self):
72        self.cell.insert([0,1,2,3,4,5,6,7])
73        assert self.cell.count() == 8
74        self.cell.split(2)
75        assert self.cell.count() == 8
76
77        self.cell.clear()
78        assert self.cell.count() == 0
79
80
81
82    def test_split(self):
83        self.cell.insert([0,1,2,3,4,5,6,7], split = False)
84
85        #No children yet
86        assert self.cell.children is None
87        assert self.cell.count() == 8
88
89        #Split
90        self.cell.split(4)
91        #self.cell.show()
92        #self.cell.show_all()
93
94
95        #Now there are children
96        assert self.cell.children is not None
97        assert self.cell.count() == 8
98
99
100
101    def test_collapse(self):
102        self.cell.insert([0,1,2,3,4,5,6,7], split = False)
103
104        #Split maximally
105        self.cell.split(1)
106
107        #Now there are children
108        assert self.cell.children is not None
109        assert self.cell.count() == 8
110
111        #Collapse
112        self.cell.collapse(8)
113
114        #No children
115        assert self.cell.children is None
116        assert self.cell.count() == 8
117
118    def test_build_quadtree(self):
119
120        Q = build_quadtree(self.mesh)
121        assert Q.count() == 8
122
123        #Q.show()
124
125        result = Q.search(3, 105)
126        assert type(result) in [types.ListType,types.TupleType],\
127                                'should be a list'
128        #print "result",result
129        self.assertEqual(result, [0,1,2,3])
130
131
132    def test_build_quadtreeII(self):
133
134        self.cell = Cell(100, 140, 0, 40, 'cell')
135
136        p0 = [34.6292076111,-7999.92529297]
137        p1 = [8000.0, 7999.0]
138        p2 = [-7999.96630859, 7999.0]
139        p3 = [34, 7999.97021484]
140
141        points = [p0,p1,p2, p3]
142        #bac, bce, ecf, dbe, daf, dae
143        vertices = [[0,1,2],[0,2,3]]
144
145        mesh = Mesh(points, vertices)
146
147        #This was causing round off error
148        Q = build_quadtree(mesh)
149
150#-------------------------------------------------------------
151if __name__ == "__main__":
152
153    mysuite = unittest.makeSuite(Test_Quad,'test')
154    runner = unittest.TextTestRunner()
155    runner.run(mysuite)
Note: See TracBrowser for help on using the repository browser.