/[escript]/trunk/downunder/test/python/run_mappings.py
ViewVC logotype

Contents of /trunk/downunder/test/python/run_mappings.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3951 - (show annotations)
Tue Aug 28 23:58:08 2012 UTC (9 years, 3 months ago) by caltinay
File MIME type: text/x-python
File size: 3079 byte(s)
Fixed tests with python versions <2.7.

1
2 ########################################################
3 #
4 # Copyright (c) 2012 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2012 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 import unittest
23 import sys
24 from esys.downunder.mappings import *
25
26 class TestScalingMapping(unittest.TestCase):
27 def setUp(self):
28 self.alpha=4.2
29 self.mapping=ScalingMapping(self.alpha)
30
31 def test_invalid_alpha(self):
32 self.assertRaises(ValueError, ScalingMapping, 0)
33
34 def test_value(self):
35 v=self.mapping.getValue(1.23)
36 ref=self.alpha*1.23
37 self.assertAlmostEqual(v, ref)
38
39 def test_derivative(self):
40 v=self.mapping.getDerivative(1.23)
41 ref=self.alpha
42 self.assertAlmostEqual(v, ref)
43
44 def test_inverse(self):
45 v=self.mapping.getInverse(1.23)
46 ref=1.23/self.alpha
47 self.assertAlmostEqual(v, ref)
48
49 class TestBoundedRangeMapping(unittest.TestCase):
50 def setUp(self):
51 self.alpha=4.2
52 self.mapping=BoundedRangeMapping(1.5, 3.5)
53
54 def test_invalid_range(self):
55 self.assertRaises(ValueError, BoundedRangeMapping, 1, 0)
56
57 def test_min_value(self):
58 v=self.mapping.getValue(-10000)
59 ref=1.5
60 self.assertAlmostEqual(v, ref)
61
62 def test_max_value(self):
63 v=self.mapping.getValue(10000)
64 ref=3.5
65 self.assertAlmostEqual(v, ref)
66
67 def test_zero_value(self):
68 v=self.mapping.getValue(0)
69 ref=2.5
70 self.assertAlmostEqual(v, ref)
71
72 def test_min_derivative(self):
73 v=self.mapping.getDerivative(-10000)
74 ref=0.
75 self.assertAlmostEqual(v, ref)
76
77 def test_max_derivative(self):
78 v=self.mapping.getDerivative(10000)
79 ref=0.
80 self.assertAlmostEqual(v, ref)
81
82 def test_zero_derivative(self):
83 v=self.mapping.getDerivative(0)
84 ref=1.
85 self.assertAlmostEqual(v, ref)
86
87 def test_inverse_toolow(self):
88 self.assertRaises(ValueError, self.mapping.getInverse, 1.5)
89
90 def test_inverse_toohigh(self):
91 self.assertRaises(ValueError, self.mapping.getInverse, 3.5)
92
93 def test_inverse(self):
94 v=self.mapping.getInverse(2.5)
95 ref=0.
96 self.assertAlmostEqual(v, ref)
97
98 if __name__ == "__main__":
99 suite = unittest.TestSuite()
100 suite.addTest(unittest.makeSuite(TestScalingMapping))
101 suite.addTest(unittest.makeSuite(TestBoundedRangeMapping))
102 s=unittest.TextTestRunner(verbosity=2).run(suite)
103 if not s.wasSuccessful(): sys.exit(1)
104

  ViewVC Help
Powered by ViewVC 1.1.26