source: anuga_core/source/anuga/utilities/test_quad.py @ 3945

Last change on this file since 3945 was 3945, checked in by ole, 17 years ago

One large step towards major cleanup. This has mainly to do with
the way vertex coordinates are handled internally.

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