source: anuga_work/development/Hinwood_2008/test_slope.py @ 5447

Last change on this file since 5447 was 5447, checked in by duncan, 15 years ago

Current Hinwood scenario

File size: 2.5 KB
Line 
1#!/usr/bin/env python
2#
3"""
4I removed lone test vert's, since I'm working on removing lone verts at a lower
5level of the code, using the -j flag in triangle.
6"""
7import sys
8import os
9import unittest
10import tempfile
11
12from scipy import array, allclose
13
14from slope import *
15
16class 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
290,0.1,0.2,0.3
300.01,0.1,0.2,1.2
310.02,0.1,0.1,0.0
320.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
680, 0, 1, 2, 1, 0, 0, 0, 0
691, 0, 0, 1, 2, 1, 0, 0, 0
702, 0, 0, 0, 1.5, 3, 1.5, 0, 0
713, 0, 0, 0, 0, 1.5, 3, 0, 0
724, 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             
80if __name__ == "__main__":
81
82    suite = unittest.makeSuite(slopeTestCase,'test')
83    runner = unittest.TextTestRunner()  #verbosity=2)
84    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.