/[escript]/trunk/escript/test/python/run_units.py
ViewVC logotype

Diff of /trunk/escript/test/python/run_units.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2398 by gross, Tue Apr 28 04:41:53 2009 UTC revision 2399 by gross, Tue Apr 28 12:04:34 2009 UTC
# Line 20  http://www.opensource.org/licenses/osl-3 Line 20  http://www.opensource.org/licenses/osl-3
20  __url__="https://launchpad.net/escript-finley"  __url__="https://launchpad.net/escript-finley"
21    
22  import unittest  import unittest
23    import sys
24  from esys.escript.unitsSI import *  from esys.escript.unitsSI import *
25  from esys.escript.util import EPSILON  from esys.escript.util import EPSILON
26    
27  class UnitsSITestCase(unittest.TestCase):  class UnitsSITestCase(unittest.TestCase):
28      TOL=EPSILON*100.      TOL=EPSILON*100.
29        def testUnit(self):
30           s=Unit("s","something",1.,4.)
31           self.failUnless(s.getName() == "s", "wrong name")
32           s.setName("t")
33           self.failUnless(s.getName() == "t", "wrong reset name")
34           self.failUnless(s.getLongName() == "something", "wrong long name")
35           s.setLongName("test")
36           self.failUnless(s.getLongName() == "test", "wrong reset long name")
37           self.failUnless(abs( s(3.)-13.) <= self.TOL*13. , " s(3.) wrong.")
38           self.failUnless(abs( 3.*s-13.) <= self.TOL*13. , " 13.s wrong.")
39           self.failUnless(abs( 10.*s-41.) <= self.TOL*41. , " 10.s wrong.")
40           self.failUnless(abs( 41./s-10.) <= self.TOL*10. , " 10/s wrong.")
41           self.failUnless(abs( 13./s-3.) <= self.TOL*3. , " 13/s wrong.")
42    
43           x=Unit("x","X",10.,2.)
44           y=Unit("y","Y",0.,4.)
45           z=Unit("z","Z",0.,0.5)
46           p_m=x*s
47           self.failUnless(p_m.getName() == "xt", "wrong p_m name")
48           self.failUnless(p_m.getLongName() == "X*test", "wrong p_m long name")
49           self.failUnless(abs(p_m(0.)-12.) <= self.TOL*12 , " p_m(0) wrong.")
50           self.failUnless(abs(p_m(1.)-20.) <= self.TOL*20 , " p_m(1) wrong.")
51    
52           p_d=y/z
53           self.failUnless(p_d.getName() == "y/z", "wrong p_d name")
54           self.failUnless(p_d.getLongName() == "Y/Z", "wrong p_d long name")
55           self.failUnless(abs(p_d(1.)-8.) <= self.TOL*8. , " p_d(0) wrong.")
56           self.failUnless(abs(p_d(2.)-16.) <= self.TOL*16. , " p_d(1) wrong.")
57    
58           p_p=y**3
59           self.failUnless(p_p.getName() == "y^3", "p_p mult name")
60           self.failUnless(p_p.getLongName() == "Y^3", "wrong p_p long name")
61           self.failUnless(abs(p_p(1.)-64.) <= self.TOL*64. , " p_p(0) wrong.")
62           self.failUnless(abs(p_p(.5)-32) <= self.TOL*32. , " p_p(1) wrong.")
63    
64            
65           x=Unit("x","X",0.,2.)
66           y=Unit("y","Y",0.,4.)
67           z=Unit("z","Z",0.,0.5)
68    
69           self.failUnless(((x*x)).getName() == "xx", "wrong name")
70           self.failUnless((x*(x*z)).getName() == "xxz", "wrong name")
71           self.failUnless((x*(x/z)).getName() == "xx/z", "wrong name")
72           self.failUnless((x*(y**3)).getName() == "x y^3", "wrong name")
73    
74           self.failUnless(((x*z)*x).getName() == "xzx", "wrong name")
75           self.failUnless(((x*z)*(x*z)).getName() == "xzxz", "wrong name")
76           self.failUnless(((x*z)*(x/z)).getName() == "xzx/z", "wrong name")
77           self.failUnless(((x*z)*(y**3)).getName() == "xz y^3", "wrong name")
78    
79           self.failUnless(((x/z)*x).getName() == "x/z x", "wrong name")
80           self.failUnless(((x/z)*(x*z)).getName() == "x/z xz", "wrong name")
81           self.failUnless(((x/z)*(x/z)).getName() == "x/z x/z", "wrong name")
82           self.failUnless(((x/z)*(y**3)).getName() == "x/z y^3", "wrong name")
83    
84           self.failUnless(((y**3)*x).getName() == "y^3 x", "wrong name")
85           self.failUnless(((y**3)*(x*z)).getName() == "y^3 xz", "wrong name")
86           self.failUnless(((y**3)*(x/z)).getName() == "y^3 x/z", "wrong name")
87           self.failUnless(((y**3)*(y**3)).getName() == "y^3 y^3", "wrong name")
88    
89           self.failUnless((x/x).getName() == "x/x", "wrong name")
90           self.failUnless((x/(x*z)).getName() == "x/(xz)", "wrong name")
91           self.failUnless((x/(x/z)).getName() == "x/(x/z)", "wrong name")
92           self.failUnless((x/(y**3)).getName() == "x/y^3", "wrong name")
93    
94           self.failUnless(((x*z)/x).getName() == "xz/x", "wrong name")
95           self.failUnless(((x*z)/(x*z)).getName() == "xz/(xz)", "wrong name")
96           self.failUnless(((x*z)/(x/z)).getName() == "xz/(x/z)", "wrong name")
97           self.failUnless(((x*z)/(y**3)).getName() == "xz/y^3", "wrong name")
98    
99           self.failUnless(((x/z)/x).getName() == "x/z/x", "wrong name")
100           self.failUnless(((x/z)/(x*z)).getName() == "x/z/(xz)", "wrong name")
101           self.failUnless(((x/z)/(x/z)).getName() == "x/z/(x/z)", "wrong name")
102           self.failUnless(((x/z)/(y**3)).getName() == "x/z/y^3", "wrong name")
103    
104           self.failUnless(((y**3)/x).getName() == "y^3/x", "wrong name")
105           self.failUnless(((y**3)/(x*z)).getName() == "y^3/(xz)", "wrong name")
106           self.failUnless(((y**3)/(x/z)).getName() == "y^3/(x/z)", "wrong name")
107           self.failUnless(((y**3)/(y**3)).getName() == "y^3/y^3", "wrong name")
108    
109           self.failUnless((x**2).getName() == "x^2", "wrong name")
110           self.failUnless(((x*z)**2).getName() == "(xz)^2", "wrong name")
111           self.failUnless(((x/z)**2).getName() == "(x/z)^2", "wrong name")
112           self.failUnless(((y**3)**2).getName() == "(y^3)^2", "wrong name")
113    
114           self.failUnless(((x*x)).getLongName() == "X*X", "wrong long name")
115           self.failUnless((x*(x*z)).getLongName() == "X*X*Z", "wrong long name")
116           self.failUnless((x*(x/z)).getLongName() == "X*X/Z", "wrong long name")
117           self.failUnless((x*(y**3)).getLongName() == "X*Y^3", "wrong long name")
118    
119           self.failUnless(((x*z)*x).getLongName() == "X*Z*X", "wrong long name")
120           self.failUnless(((x*z)*(x*z)).getLongName() == "X*Z*X*Z", "wrong long name")
121           self.failUnless(((x*z)*(x/z)).getLongName() == "X*Z*X/Z", "wrong long name")
122           self.failUnless(((x*z)*(y**3)).getLongName() == "X*Z*Y^3", "wrong long name")
123    
124           self.failUnless(((x/z)*x).getLongName() == "X/Z*X", "wrong long name")
125           self.failUnless(((x/z)*(x*z)).getLongName() == "X/Z*X*Z", "wrong long name")
126           self.failUnless(((x/z)*(x/z)).getLongName() == "X/Z*X/Z", "wrong long name")
127           self.failUnless(((x/z)*(y**3)).getLongName() == "X/Z*Y^3", "wrong long name")
128    
129           self.failUnless(((y**3)*x).getLongName() == "Y^3*X", "wrong long name")
130           self.failUnless(((y**3)*(x*z)).getLongName() == "Y^3*X*Z", "wrong long name")
131           self.failUnless(((y**3)*(x/z)).getLongName() == "Y^3*X/Z", "wrong long name")
132           self.failUnless(((y**3)*(y**3)).getLongName() == "Y^3*Y^3", "wrong long name")
133    
134           self.failUnless((x/x).getLongName() == "X/X", "wrong long name")
135           self.failUnless((x/(x*z)).getLongName() == "X/(X*Z)", "wrong long name")
136           self.failUnless((x/(x/z)).getLongName() == "X/(X/Z)", "wrong long name")
137           self.failUnless((x/(y**3)).getLongName() == "X/Y^3", "wrong long name")
138    
139           self.failUnless(((x*z)/x).getLongName() == "X*Z/X", "wrong long name")
140           self.failUnless(((x*z)/(x*z)).getLongName() == "X*Z/(X*Z)", "wrong long name")
141           self.failUnless(((x*z)/(x/z)).getLongName() == "X*Z/(X/Z)", "wrong long name")
142           self.failUnless(((x*z)/(y**3)).getLongName() == "X*Z/Y^3", "wrong long name")
143    
144           self.failUnless(((x/z)/x).getLongName() == "X/Z/X", "wrong long name")
145           self.failUnless(((x/z)/(x*z)).getLongName() == "X/Z/(X*Z)", "wrong long name")
146           self.failUnless(((x/z)/(x/z)).getLongName() == "X/Z/(X/Z)", "wrong long name")
147           self.failUnless(((x/z)/(y**3)).getLongName() == "X/Z/Y^3", "wrong long name")
148    
149           self.failUnless(((y**3)/x).getLongName() == "Y^3/X", "wrong long name")
150           self.failUnless(((y**3)/(x*z)).getLongName() == "Y^3/(X*Z)", "wrong long name")
151           self.failUnless(((y**3)/(x/z)).getLongName() == "Y^3/(X/Z)", "wrong long name")
152           self.failUnless(((y**3)/(y**3)).getLongName() == "Y^3/Y^3", "wrong long name")
153    
154           self.failUnless((x**2).getLongName() == "X^2", "wrong long name")
155           self.failUnless(((x*z)**2).getLongName() == "(X*Z)^2", "wrong long name")
156           self.failUnless(((x/z)**2).getLongName() == "(X/Z)^2", "wrong long name")
157           self.failUnless(((y**3)**2).getLongName() == "(Y^3)^2", "wrong long name")
158    
159      def testPrefix(self):      def testPrefix(self):
160         self.failUnless(abs( Yotta * Yocto - 1.) <= self.TOL , " Yotta or Yocto wrong.")         self.failUnless(abs( Yotta * Yocto - 1.) <= self.TOL , " Yotta or Yocto wrong.")
161         self.failUnless(abs( Zetta * Zepto - 1.) <= self.TOL , "  Zetta or Zepto  wrong.")         self.failUnless(abs( Zetta * Zepto - 1.) <= self.TOL , "  Zetta or Zepto  wrong.")
# Line 62  class UnitsSITestCase(unittest.TestCase) Line 193  class UnitsSITestCase(unittest.TestCase)
193         self.failUnless(abs( N- 1.) <= self.TOL , " N wrong.")         self.failUnless(abs( N- 1.) <= self.TOL , " N wrong.")
194      def testPressure(self):      def testPressure(self):
195         self.failUnless(abs( Pa- 1.) <= self.TOL , " Pa wrong.")         self.failUnless(abs( Pa- 1.) <= self.TOL , " Pa wrong.")
196         self.failUnless(abs( atm- 101325.024) <= self.TOL*101,325.024 , " Pa wrong.")         self.failUnless(abs( atm- 101325.024) <= self.TOL*101325.024 , " Pa wrong.")
197      def testEnegry(self):      def testEnegry(self):
198         self.failUnless(abs( J- 1.) <= self.TOL , " J wrong.")         self.failUnless(abs( J- 1.) <= self.TOL , " J wrong.")
199      def testPower(self):      def testPower(self):

Legend:
Removed from v.2398  
changed lines
  Added in v.2399

  ViewVC Help
Powered by ViewVC 1.1.26