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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2403 - (show annotations)
Wed Apr 29 06:08:18 2009 UTC (10 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 22666 byte(s)
units support Celsius, Farenheit and kelvin now
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 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) 2003-2008 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.escript.unitsSI import *
25 from esys.escript.util import EPSILON
26
27 class UnitsSITestCase(unittest.TestCase):
28 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):
160
161
162 self.failUnless(Yotta.getName() == "Y","Yotta name wrong")
163 self.failUnless(Zetta.getName() == "Z","Zetta name wrong")
164 self.failUnless(Exa.getName() == "E","Exa name wrong")
165 self.failUnless(Peta.getName() == "P","Peta name wrong")
166 self.failUnless(Tera.getName() == "T","Tera name wrong")
167 self.failUnless(Giga.getName() == "G","Giga name wrong")
168 self.failUnless(Mega.getName() == "M","Mega name wrong")
169 self.failUnless(Kilo.getName() == "k","Kilo name wrong")
170 self.failUnless(Hecto.getName() == "h","Hecto name wrong")
171 self.failUnless(Deca.getName() == "da","Deca name wrong")
172 self.failUnless(Deci.getName() == "d","Deci name wrong")
173 self.failUnless(Centi.getName() == "c","Centi name wrong")
174 self.failUnless(Milli.getName() == "m","Milli name wrong")
175 self.failUnless(Micro.getName() == "mu","Micro name wrong")
176 self.failUnless(Nano.getName() == "n","Nano name wrong")
177 self.failUnless(Pico.getName() == "p","Pico name wrong")
178 self.failUnless(Femto.getName() == "f","Femto name wrong")
179 self.failUnless(Atto.getName() == "a","Atto name wrong")
180 self.failUnless(Zepto.getName() == "z","Zepto name wrong")
181 self.failUnless(Yocto.getName() == "y","Yocto name wrong")
182
183 self.failUnless(Yotta.getLongName() == "Yotta","wrong long name")
184 self.failUnless(Zetta.getLongName() == "Zetta","wrong long name")
185 self.failUnless(Exa.getLongName() == "Exa","wrong long name")
186 self.failUnless(Peta.getLongName() == "Peta","wrong long name")
187 self.failUnless(Tera.getLongName() == "Tera","wrong long name")
188 self.failUnless(Giga.getLongName() == "Giga","wrong long name")
189 self.failUnless(Mega.getLongName() == "Mega","wrong long name")
190 self.failUnless(Kilo.getLongName() == "Kilo","wrong long name")
191 self.failUnless(Hecto.getLongName() == "Hecto","wrong long name")
192 self.failUnless(Deca.getLongName() == "Deca","wrong long name")
193 self.failUnless(Deci.getLongName() == "Deci","wrong long name")
194 self.failUnless(Centi.getLongName() == "Centi","wrong long name")
195 self.failUnless(Milli.getLongName() == "Milli","wrong long name")
196 self.failUnless(Micro.getLongName() == "Micro","wrong long name")
197 self.failUnless(Nano.getLongName() == "Nano","wrong long name")
198 self.failUnless(Pico.getLongName() == "Pico","wrong long name")
199 self.failUnless(Femto.getLongName() == "Femto","wrong long name")
200 self.failUnless(Atto.getLongName() == "Atto","wrong long name")
201 self.failUnless(Zepto.getLongName() == "Zepto","wrong long name")
202 self.failUnless(Yocto.getLongName() == "Yocto","wrong long name")
203
204 self.failUnless(abs(Yotta(1.)/1.e24 -1.) <= self.TOL , "wrong b value")
205 self.failUnless(abs(Zetta(1.)/1.e21 -1.) <= self.TOL , "wrong b value")
206 self.failUnless(abs(Exa(1.)/1.e18 -1.) <= self.TOL , "wrong b value")
207 self.failUnless(abs(Peta(1.)/1.e15 -1.) <= self.TOL , "wrong b value")
208 self.failUnless(abs(Tera(1.)/1.e12 -1.) <= self.TOL , "wrong b value")
209 self.failUnless(abs(Giga(1.)/1.e9 -1.) <= self.TOL , "wrong b value")
210 self.failUnless(abs(Mega(1.)/1.e6 -1.) <= self.TOL , "wrong b value")
211 self.failUnless(abs(Kilo(1.)/1.e3 -1.) <= self.TOL , "wrong b value")
212 self.failUnless(abs(Hecto(1.)/1.e2 -1.) <= self.TOL , "wrong b value")
213 self.failUnless(abs(Deca(1.)/1.e1 -1.) <= self.TOL , "wrong b value")
214 self.failUnless(abs(Deci(1.)/1.e-1 -1.) <= self.TOL , "wrong b value")
215 self.failUnless(abs(Centi(1.)/1.e-2 -1.) <= self.TOL , "wrong b value")
216 self.failUnless(abs(Milli(1.)/1.e-3 -1.) <= self.TOL , "wrong b value")
217 self.failUnless(abs(Micro(1.)/1.e-6 -1.) <= self.TOL , "wrong b value")
218 self.failUnless(abs(Nano(1.)/1.e-9 -1.) <= self.TOL , "wrong b value")
219 self.failUnless(abs(Pico(1.)/1.e-12 -1.) <= self.TOL , "wrong b value")
220 self.failUnless(abs(Femto(1.)/1.e-15 -1.) <= self.TOL , "wrong b value")
221 self.failUnless(abs(Atto(1.)/1.e-18 -1.) <= self.TOL , "wrong b value")
222 self.failUnless(abs(Zepto(1.)/1.e-21 -1.) <= self.TOL , "wrong b value")
223 self.failUnless(abs(Yocto(1.)/1.e-24 -1.) <= self.TOL , "wrong b value")
224
225 self.failUnless(abs( Yotta(1.) * Yocto(1.) - 1.) <= self.TOL , " Yotta or Yocto wrong.")
226 self.failUnless(Yotta(0.) == 0. , " Yotta a value wrong.")
227 self.failUnless(Yocto(0.) == 0. , " Yocto a value wrong.")
228 self.failUnless(abs( Zetta(1.) * Zepto(1.) - 1.) <= self.TOL , " Zetta or Zepto wrong.")
229 self.failUnless(Zetta(0.) == 0. , " Zetta a value wrong.")
230 self.failUnless(Zepto(0.) == 0. , " Zepto a value wrong.")
231 self.failUnless(abs( Exa(1.) * Atto(1.) - 1.) <= self.TOL , " Exa or Atto wrong.")
232 self.failUnless(Exa(0.) == 0. , " Exa a value wrong.")
233 self.failUnless(Atto(0.) == 0. , " Atto a value wrong.")
234 self.failUnless(abs( Peta(1.) *Femto(1.) - 1.) <= self.TOL , " Peta or Femto wrong.")
235 self.failUnless(Peta(0.) == 0. , " Peta a value wrong.")
236 self.failUnless(Femto(0.) == 0. , " Femto a value wrong.")
237 self.failUnless(abs( Tera(1.) * Pico(1.) - 1.) <= self.TOL , " Tera or Pico wrong.")
238 self.failUnless(Tera(0.) == 0. , " Tera a value wrong.")
239 self.failUnless(Pico(0.) == 0. , " Pico a value wrong.")
240 self.failUnless(abs( Giga(1.) * Nano(1.) - 1.) <= self.TOL , " Giga or Nano wrong.")
241 self.failUnless(Giga(0.) == 0. , " Giga a value wrong.")
242 self.failUnless(Nano(0.) == 0. , " Nano a value wrong.")
243 self.failUnless(abs( Mega(1.) *Micro(1.) - 1.) <= self.TOL , " Mega or Micro wrong.")
244 self.failUnless(Mega(0.) == 0. , "Mega a value wrong.")
245 self.failUnless(Micro(0.) == 0. , " Micro a value wrong.")
246 self.failUnless(abs( Kilo(1.) * Milli(1.) - 1.) <= self.TOL , "Kilo or Milli wrong.")
247 self.failUnless( Kilo(0.) == 0. , "Kilo a value wrong.")
248 self.failUnless(Milli(0.) == 0. , "Milli a value wrong.")
249 self.failUnless(abs( Hecto(1.) * Centi(1.)- 1.) <= self.TOL , " Hecto or Centi wrong.")
250 self.failUnless(Hecto(0.) == 0., " Hecto a value wrong.")
251 self.failUnless(Centi(0.)== 0. , " Centi a value wrong.")
252 self.failUnless(abs( Deca(1.) * Deci(1.) - 1.) <= self.TOL , "Deca or Deci wrong.")
253 self.failUnless(Deca(0.) == 0. , "Deca a value wrong.")
254 self.failUnless(Deci(0.) == 0. , "Deci a value wrong.")
255 def testLength(self):
256 self.failUnless(m.getName() == "m", "meter name wrong.")
257 self.failUnless(m.getLongName() == "meter", "meter long name wrong.")
258 self.failUnless(abs( m(1.) - 1.) <= self.TOL , " meter wrong.")
259 self.failUnless(abs( km(1.) - 1000.) <= self.TOL*1000. , " km wrong.")
260 self.failUnless(abs( cm(1.) - 1./100.) <= self.TOL/100. , " cm wrong.")
261 self.failUnless(abs( mm(1.) - 1./1000.) <= self.TOL/1000. , " mm wrong.")
262 self.failUnless(m(0.) == 0., " meter wrong.")
263 self.failUnless(km(0.) == 0., " km wrong.")
264 self.failUnless(cm(0.) == 0. , " cm wrong.")
265 self.failUnless(mm(0.) ==0.," mm wrong.")
266 def testTime(self):
267 self.failUnless(sec.getName() == "sec" , "sec name wrong")
268 self.failUnless(sec.getLongName() == "second" , "sec long name wrong")
269 self.failUnless(minute.getName() == "min" , "minute name wrong")
270 self.failUnless(minute.getLongName() == "minute" , "minute long name wrong")
271 self.failUnless(h.getName() == "h" , "hour name wrong")
272 self.failUnless(h.getLongName() == "hour" , "hour long name wrong")
273 self.failUnless(day.getName() == "d" , "day name wrong")
274 self.failUnless(day.getLongName() == "day" , "day long name wrong")
275 self.failUnless(yr.getName() == "yr" , "year name wrong")
276 self.failUnless(yr.getLongName() == "year" , "year long name wrong")
277
278 self.failUnless(abs( sec(1.) - 1.) <= self.TOL , " second wrong.")
279 self.failUnless(abs( minute(1.) - 60.) <= self.TOL*60 , " minute wrong.")
280 self.failUnless(abs( h(1.) - 3600) <= self.TOL*3600., " h wrong.")
281 self.failUnless(abs( day(1.) - 86400.) <= self.TOL*86400 , " day wrong.")
282 self.failUnless(abs( yr(1.) - 31556952) <= self.TOL*31556952 , " yr wrong.")
283 self.failUnless(abs( Myr(1.) - 31556952.e6) <= self.TOL*31556952.e6 , " Myr wrong.")
284 self.failUnless(abs( Gyr(1.) - 31556952.e9) <= self.TOL*31556952.e9 , " Gyr wrong.")
285
286 self.failUnless(sec(0.) == 0. , " second wrong.")
287 self.failUnless(minute(0.) == 0. , " minute wrong.")
288 self.failUnless(h(0.) == 0., " h wrong.")
289 self.failUnless(day(0.) == 0. , " day wrong.")
290 self.failUnless(yr(0.) == 0. , " yr wrong.")
291 self.failUnless(Myr(0.) == 0. , " Myr wrong.")
292 self.failUnless(Gyr(0.) == 0., " Gyr wrong.")
293 def testMass(self):
294 self.failUnless(kg.getName() == "kg" , " kg wrong.")
295 self.failUnless(lb.getName() == "lb" , " lb wrong.")
296 self.failUnless(kg.getLongName() == "kg" , " kg wrong.")
297 self.failUnless(lb.getLongName() == "pound" , " lb wrong.")
298
299 self.failUnless(abs( gram(1.) - 1./1000.) <= self.TOL/1000. , " gram wrong.")
300 self.failUnless(abs( kg(1.) - 1.) <= self.TOL , " kg wrong.")
301 self.failUnless(abs( ton(1.) - 1.e3) <= self.TOL*1.e3 , " ton wrong.")
302 self.failUnless(abs( lb(1.) - 0.45359237) <= self.TOL , " lb wrong.")
303
304 self.failUnless(gram(0.) == 0. , " gram wrong.")
305 self.failUnless(kg(0.) == 0. , " kg wrong.")
306 self.failUnless(ton(0.) == 0. , " ton wrong.")
307 self.failUnless(lb(0.) == 0. , " lb wrong.")
308
309 def testCurrent(self):
310 self.failUnless(A.getName() == "A" , " A wrong.")
311 self.failUnless(A.getLongName() == "Ampere" , " A wrong.")
312 self.failUnless(A(0.) == 0. , " A wrong.")
313 self.failUnless(abs( A(1.)- 1.) <= self.TOL , " A wrong.")
314 def testFrequency(self):
315 self.failUnless(Hz(0.) == 0. , " Hz wrong.")
316 self.failUnless(abs( Hz(1)- 1.) <= self.TOL , " Hz wrong.")
317
318 def testForce(self):
319 self.failUnless(N.getName() == "N" , "N wrong.")
320 self.failUnless(N.getLongName() == "Newton" , " N wrong.")
321 self.failUnless(N(0.) == 0. , " N wrong.")
322 self.failUnless(abs( N(1)- 1.) <= self.TOL , " N wrong.")
323 def testPressure(self):
324 self.failUnless(Pa.getName() == "Pa" , " Pa wrong.")
325 self.failUnless(Pa.getLongName() == "Pascal" , " Pa wrong.")
326 self.failUnless(Pa(0.) == 0. , " Pa wrong.")
327 self.failUnless(abs( Pa(1)- 1.) <= self.TOL , " Pa wrong.")
328
329 self.failUnless(atm.getName() == "atm" , " atm wrong.")
330 self.failUnless(atm.getLongName() == "atmosphere" , " atm wrong.")
331 self.failUnless(atm(0.) == 0. , " atm wrong.")
332 self.failUnless(abs( atm(1)- 101325.024) <= self.TOL*101325.024 , " atm wrong.")
333
334 def testEnegry(self):
335 self.failUnless(J.getName() == "J" , " J wrong.")
336 self.failUnless(J.getLongName() == "Joule" , " J wrong.")
337 self.failUnless(J(0.) == 0. , " J wrong.")
338 self.failUnless(abs( J(1)- 1.) <= self.TOL , " J wrong.")
339
340 def testPower(self):
341 self.failUnless(W.getName() == "W" , " W wrong.")
342 self.failUnless(W.getLongName() == "Watt" , " W wrong.")
343 self.failUnless(W(0.) == 0. , " W wrong.")
344 self.failUnless(abs( W(1)- 1.) <= self.TOL , " W wrong.")
345
346 def testPotential(self):
347 self.failUnless(V.getName() == "V" , " V wrong.")
348 self.failUnless(V.getLongName() == "Volt" , " V wrong.")
349 self.failUnless(V(0.) == 0. , " V wrong.")
350 self.failUnless(abs( V(1)- 1.) <= self.TOL , " V wrong.")
351
352 def testCharge(self):
353 self.failUnless(C.getName() == "C" , " C wrong.")
354 self.failUnless(C.getLongName() == "Coulomb" , " C wrong.")
355 self.failUnless(C(0.) == 0. , " C wrong.")
356 self.failUnless(abs( C(1)- 1.) <= self.TOL , " C wrong.")
357
358 def testResistance(self):
359 self.failUnless(Ohm.getName() == "Ohm" , " Ohm wrong.")
360 self.failUnless(Ohm.getLongName() == "Ohm" , " Ohm wrong.")
361 self.failUnless(Ohm(0.) == 0. , " Ohm wrong.")
362 self.failUnless(abs( Ohm(1)- 1.) <= self.TOL , " Ohm wrong.")
363 def testTemperature(self):
364 self.failUnless(K.getName() == "K" , " Kelvin wrong.")
365 self.failUnless(K.getLongName() == "Kelvin" , " Kelvin wrong.")
366 self.failUnless(K(0.) == 0. , " Kelvin wrong.")
367 self.failUnless(abs( K(1.)- 1.) <= self.TOL , " Kelvin wrong.")
368
369 self.failUnless(Celsius.getName() == "C" , " Celsius wrong.")
370 self.failUnless(Celsius.getLongName() == "Celsius" , " Celsius wrong.")
371 self.failUnless(abs(Celsius(20.) - 293.15) <= self.TOL*293.15 , " Celsius 20 conversion wrong.")
372 self.failUnless(abs(Celsius(-2.)- 271.15) <= self.TOL*271.15 , " Celsius conversion wrong.")
373 self.failUnless(abs(Celsius(100.)- 373.15) <= self.TOL*373.15 , " Celsius conversion wrong.")
374
375 self.failUnless(Fahrenheit.getName() == "F" , " Fahrenheit wrong.")
376 self.failUnless(Fahrenheit.getLongName() == "Fahrenheit" , " Fahrenheit wrong.")
377 self.failUnless(abs( Fahrenheit(0.)- 255.3722222) <= 1.e-8*255.3722222, " Fahrenheit wrong.")
378 self.failUnless(abs( Fahrenheit(20.)- 266.4833333) <= 1.e-8*266.4833333 , " Fahrenheit wrong.")
379 self.failUnless(abs( Fahrenheit(100.)- 310.9277778 ) <= 1.e-8 * 310.9277778 , " Fahrenheit wrong.")
380 self.failUnless(abs( Fahrenheit(-1.)- 254.8166667) <= 1.e-8 *254.8166667, "Fahrenheit wrong.")
381
382
383 def testEarth(self):
384 R=6367444.65
385 self.failUnless(abs( R_Earth_equator-6378137) <= self.TOL*R , " R_Earth_equator wrong.")
386 self.failUnless(abs( R_Earth_poles-6356752.3) <= self.TOL*R , " R_Earth_poles wrong.")
387 self.failUnless(abs( R_Earth-R) <= self.TOL*R , "R_Earth wrong.")
388 def testVlight(self):
389 self.failUnless(abs(v_light - 299792458.) <= self.TOL*299792458. , " speed of light is wrong.")
390
391 if __name__ == "__main__":
392 suite = unittest.TestSuite()
393 suite.addTest(unittest.makeSuite(UnitsSITestCase))
394 s=unittest.TextTestRunner(verbosity=2).run(suite)
395 if not s.wasSuccessful(): sys.exit(1)

  ViewVC Help
Powered by ViewVC 1.1.26