source: inundation/ga/storm_surge/pyvolution-1d/test_domain.py @ 989

Last change on this file since 989 was 279, checked in by steve, 21 years ago

Working on Quantities

File size: 2.5 KB
RevLine 
[214]1#!/usr/bin/env python
2
3import unittest
4from math import sqrt
5
6from domain import *
7from Numeric import allclose, array
8
9
10class TestCase(unittest.TestCase):
11    def setUp(self):
[279]12        pass
13
14
15    def tearDown(self):
16        pass
17
18
19    def test_construct(self):
20
[214]21        a = 0.0
22        b = 2.0
23        c = 2.5
24        d = 3.0
25        e = 10.0
26        f = 12.0
27
28        points = [a, b, c, d, e, f]
29
[279]30        domain = Domain(points) 
31        assert allclose(domain.get_centroids(),[(a+b)*0.5, (b+c)*0.5, (c+d)*0.5, (d+e)*0.5, (e+f)*0.5])
[214]32
[256]33
[279]34    def test_area(self):
[256]35
[279]36        a = 0.0
37        b = 2.0
38        c = 2.5
39        d = 3.0
40        e = 10.0
41        f = 12.0
[256]42
[279]43        points = [a, b, c, d, e, f]
44
45        domain = Domain(points) 
46        assert allclose(domain.get_area(0),b-a)
47        assert allclose(domain.get_area(1),c-b)
48        assert allclose(domain.get_area(2),d-c)
49        assert allclose(domain.get_area(3),e-d)
50        assert allclose(domain.get_area(4),f-e)
51       
[214]52    def test_in_order(self):
53        a = 0.0
54        b = 2.0
55        c = 2.5
56        d = 3.0
57        e = 10.0
58        f = 12.0
59
60        points = [a, c, b, d, e, f]
61
62        try:
63            domain = Domain(points)
64        except:
65            pass
66        else:
67            msg = 'Should have raised exception'
68            raise msg
[256]69
70    def test_point(self):
71        a = 0.0
72        b = 2.0
73        c = 2.5
74        d = 3.0
75
76        points = [a, b, c, d]
77
78        domain = Domain(points)
79
[279]80        assert allclose(domain.get_coordinate(0), 0.5*(a+b))
81        assert allclose(domain.get_coordinate(1), 0.5*(b+c))
82        assert allclose(domain.get_coordinate(2), 0.5*(c+d))
[214]83       
[256]84        try:
[279]85            allclose(domain.get_coordinate(3), 0.5*(a+b))
[256]86        except:
87            pass
88        else:
89            msg = 'Should have raised exception'
90            raise msg
[214]91       
[279]92        assert allclose(domain.get_coordinate(0,0), a)
93        assert allclose(domain.get_coordinate(1,0), b)
94        assert allclose(domain.get_coordinate(2,0), c)
[256]95
[279]96        assert allclose(domain.get_coordinate(0,1), b)
97        assert allclose(domain.get_coordinate(1,1), c)
98        assert allclose(domain.get_coordinate(2,1), d)
[256]99
100
[214]101       
[256]102       
[214]103#-------------------------------------------------------------
104if __name__ == "__main__":
105    suite = unittest.makeSuite(TestCase,'test')
106    runner = unittest.TextTestRunner()
107    runner.run(suite)
Note: See TracBrowser for help on using the repository browser.