1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | #TEST |
---|
4 | |
---|
5 | import unittest |
---|
6 | from Numeric import allclose |
---|
7 | |
---|
8 | from alpha_shape import * |
---|
9 | |
---|
10 | class TestCase(unittest.TestCase): |
---|
11 | |
---|
12 | def setUp(self): |
---|
13 | pass |
---|
14 | |
---|
15 | |
---|
16 | def tearDown(self): |
---|
17 | pass |
---|
18 | |
---|
19 | |
---|
20 | def test_alpha(self): |
---|
21 | a = [0.0, 0.0] |
---|
22 | b = [1.0, 0.0] |
---|
23 | c = [2.0, 0.0] |
---|
24 | d = [2.0, 2.0] |
---|
25 | e = [1.0, 2.0] |
---|
26 | f = [0.0, 2.0] |
---|
27 | |
---|
28 | alpha = Alpha_Shape([a,b,c,d,e,f]) |
---|
29 | result = alpha.get_boundary() |
---|
30 | answer = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]] |
---|
31 | #print "result",result |
---|
32 | assert allclose(answer, result) |
---|
33 | |
---|
34 | |
---|
35 | def test_not_enough_points(self): |
---|
36 | a = [0.0, 0.0] |
---|
37 | b = [1.0, 0.0] |
---|
38 | |
---|
39 | try: |
---|
40 | alpha = Alpha_Shape([a,b]) |
---|
41 | except PointError: |
---|
42 | pass |
---|
43 | else: |
---|
44 | self.failUnless(0==1, |
---|
45 | 'point list with 2 points did not raise an error!') |
---|
46 | |
---|
47 | |
---|
48 | def test_alpha_stand_alone(self): |
---|
49 | import os |
---|
50 | import tempfile |
---|
51 | |
---|
52 | fileName = tempfile.mktemp(".xya") |
---|
53 | file = open(fileName,"w") |
---|
54 | file.write("title row \n\ |
---|
55 | 0.0, 0.0\n\ |
---|
56 | 1.0, 0.0\n\ |
---|
57 | 2.0, 0.0\n\ |
---|
58 | 2.0, 2.0\n\ |
---|
59 | 1.0, 2.0\n\ |
---|
60 | 0.0, 2.0\n") |
---|
61 | file.close() |
---|
62 | |
---|
63 | output_file_name = tempfile.mktemp(".bnd") |
---|
64 | command = 'python .\\alpha_shape.py ' + fileName + ' ' + output_file_name |
---|
65 | #print "command", command |
---|
66 | os.system(command) |
---|
67 | os.remove(fileName) |
---|
68 | |
---|
69 | file = open(output_file_name,"r") |
---|
70 | lFile = file.read().split('\n') |
---|
71 | file.close() |
---|
72 | os.remove(output_file_name) |
---|
73 | self.failUnless(lFile[1] == "0,1" and |
---|
74 | lFile[2] == "1,2" and |
---|
75 | lFile[3] == "2,3" and |
---|
76 | lFile[4] == "3,4" and |
---|
77 | lFile[5] == "4,5" and |
---|
78 | lFile[6] == "5,0" and |
---|
79 | lFile[7] == "" |
---|
80 | , |
---|
81 | 'boundary file is wrong') |
---|
82 | |
---|
83 | |
---|
84 | #------------------------------------------------------------- |
---|
85 | if __name__ == "__main__": |
---|
86 | suite = unittest.makeSuite(TestCase,'test') |
---|
87 | runner = unittest.TextTestRunner(verbosity=1) |
---|
88 | runner.run(suite) |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|