1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | from culvert_polygons import * |
---|
4 | |
---|
5 | import unittest |
---|
6 | import os.path |
---|
7 | |
---|
8 | from Numeric import choose, greater, ones, sin, exp, cosh, allclose |
---|
9 | from anuga.utilities.polygon import inside_polygon, polygon_area |
---|
10 | |
---|
11 | |
---|
12 | class Test_poly(unittest.TestCase): |
---|
13 | def setUp(self): |
---|
14 | pass |
---|
15 | |
---|
16 | def tearDown(self): |
---|
17 | pass |
---|
18 | |
---|
19 | |
---|
20 | def test_1(self): |
---|
21 | |
---|
22 | end_point0=[307138.813,6193474] |
---|
23 | end_point1=[307150.563,6193469] |
---|
24 | width=3 |
---|
25 | height=3 |
---|
26 | number_of_barrels=1 |
---|
27 | |
---|
28 | P = create_culvert_polygons(end_point0, |
---|
29 | end_point1, |
---|
30 | width=width, |
---|
31 | height=height, |
---|
32 | number_of_barrels=number_of_barrels) |
---|
33 | |
---|
34 | # Compute area and check that it is greater than 0 |
---|
35 | for key in ['exchange_polygon0', |
---|
36 | 'exchange_polygon1', |
---|
37 | 'enquiry_polygon0', |
---|
38 | 'enquiry_polygon1']: |
---|
39 | polygon = P[key] |
---|
40 | area = polygon_area(polygon) |
---|
41 | |
---|
42 | msg = 'Polygon %s ' %(polygon) |
---|
43 | msg += ' has area = %f' % area |
---|
44 | assert area > 0.0, msg |
---|
45 | |
---|
46 | |
---|
47 | def test_2(self): |
---|
48 | #end_point0=[307138.813,6193474] |
---|
49 | #end_point1=[307150.563,6193469] |
---|
50 | end_point0=[10., 5.] |
---|
51 | end_point1=[10., 10.] |
---|
52 | width = 1 |
---|
53 | height = 3.5 |
---|
54 | number_of_barrels=1 |
---|
55 | |
---|
56 | P = create_culvert_polygons(end_point0, |
---|
57 | end_point1, |
---|
58 | width=width, |
---|
59 | height=height, |
---|
60 | number_of_barrels=number_of_barrels) |
---|
61 | |
---|
62 | # Compute area and check that it is greater than 0 |
---|
63 | for key in ['exchange_polygon0', |
---|
64 | 'exchange_polygon1', |
---|
65 | 'enquiry_polygon0', |
---|
66 | 'enquiry_polygon1']: |
---|
67 | polygon = P[key] |
---|
68 | area = polygon_area(polygon) |
---|
69 | |
---|
70 | msg = 'Polygon %s ' % (polygon) |
---|
71 | msg += ' has area = %f' % area |
---|
72 | assert area > 0.0, msg |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | #------------------------------------------------------------- |
---|
78 | if __name__ == "__main__": |
---|
79 | suite = unittest.makeSuite(Test_poly, 'test') |
---|
80 | runner = unittest.TextTestRunner() |
---|
81 | runner.run(suite) |
---|
82 | |
---|