1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | """ |
---|
4 | I removed lone test vert's, since I'm working on removing lone verts at a lower |
---|
5 | level of the code, using the -j flag in triangle. |
---|
6 | """ |
---|
7 | import sys |
---|
8 | import os |
---|
9 | import unittest |
---|
10 | import tempfile |
---|
11 | |
---|
12 | from scipy import array, allclose |
---|
13 | |
---|
14 | from slope import * |
---|
15 | |
---|
16 | class slopeTestCase(unittest.TestCase): |
---|
17 | def setUp(self): |
---|
18 | pass |
---|
19 | |
---|
20 | def tearDown(self): |
---|
21 | pass |
---|
22 | |
---|
23 | def test_slope_from_file(self): |
---|
24 | handle, file_name = tempfile.mkstemp('.csv', __name__+'_') |
---|
25 | os.close(handle) |
---|
26 | handle = open(file_name,'w') |
---|
27 | |
---|
28 | sample = """time,0.5:0.5,0.501:0.5,0.502:0.5 |
---|
29 | 0,0.1,0.2,0.3 |
---|
30 | 0.01,0.1,0.2,1.2 |
---|
31 | 0.02,0.1,0.1,0.0 |
---|
32 | 0.03,0.5,0.501,0.502""" |
---|
33 | handle.write(sample) |
---|
34 | handle.close() |
---|
35 | dtimes, depths, sensors = load_depths(file_name) |
---|
36 | actual = array([0,0.01,0.02,0.03]) |
---|
37 | self.assert_ (allclose(dtimes, actual, 0.001)) |
---|
38 | actual = array([0.5, 0.501, 0.502]) |
---|
39 | self.assert_ (allclose(depths, actual, 0.001)) |
---|
40 | |
---|
41 | actual = array([[ 0.1, 0.2, 0.3 ], |
---|
42 | [ 0.1 , 0.2 , 1.2 ], |
---|
43 | [ 0.1 , 0.1, 0. ], |
---|
44 | [ 0.5 , 0.501 , 0.502]]) |
---|
45 | self.assert_ (allclose(sensors, actual, 0.001)) |
---|
46 | |
---|
47 | times, slope_locations, slopes = load_slopes(file_name) |
---|
48 | actual = array([0.5005, 0.5015]) |
---|
49 | self.assert_ (allclose(slope_locations, actual, 0.001)) |
---|
50 | actual = array([0,0.01,0.02,0.03]) |
---|
51 | self.assert_ (allclose(times, actual, 0.001)) |
---|
52 | |
---|
53 | actual = array([[ 100., 100.], |
---|
54 | [ 100., 1000.], |
---|
55 | [ 0., -100.], |
---|
56 | [ 1., 1.]]) |
---|
57 | self.assert_ (allclose(slopes, actual, 0.001)) |
---|
58 | |
---|
59 | |
---|
60 | os.remove(file_name) |
---|
61 | |
---|
62 | def test_plot_from_file(self): |
---|
63 | handle, file_name = tempfile.mkstemp('.csv', __name__+'_') |
---|
64 | os.close(handle) |
---|
65 | handle = open(file_name,'w') |
---|
66 | |
---|
67 | sample = """time,0.0:1,1:0.5,2:0.5,3:0.5,4:0.5,5:0.5,6:0.5,7:0.5 |
---|
68 | 0, 0, 1, 2, 1, 0, 0, 0, 0 |
---|
69 | 1, 0, 0, 1, 2, 1, 0, 0, 0 |
---|
70 | 2, 0, 0, 0, 1.5, 3, 1.5, 0, 0 |
---|
71 | 3, 0, 0, 0, 0, 1.5, 3, 0, 0 |
---|
72 | 4, 0, 0, 0, 0, 0, 1.5, 3, 0""" |
---|
73 | handle.write(sample) |
---|
74 | handle.close() |
---|
75 | graph_slopes(file_name) |
---|
76 | |
---|
77 | |
---|
78 | os.remove(file_name) |
---|
79 | |
---|
80 | if __name__ == "__main__": |
---|
81 | |
---|
82 | suite = unittest.makeSuite(slopeTestCase,'test') |
---|
83 | runner = unittest.TextTestRunner() #verbosity=2) |
---|
84 | runner.run(suite) |
---|