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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4938 - (show annotations)
Wed May 14 01:13:23 2014 UTC (5 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 22828 byte(s)
Modify unit tests to read their classes from
esys.escriptcore.utestselect

Change the line in that file to switch between unittest and unittest2


1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 import esys.escriptcore.utestselect as unittest
25 import sys
26 from esys.escript.unitsSI import *
27 from esys.escript.util import EPSILON
28
29 class UnitsSITestCase(unittest.TestCase):
30 TOL=EPSILON*100.
31 def testUnit(self):
32 s=Unit("s","something",1.,4.)
33 self.assertTrue(s.getName() == "s", "wrong name")
34 s.setName("t")
35 self.assertTrue(s.getName() == "t", "wrong reset name")
36 self.assertTrue(s.getLongName() == "something", "wrong long name")
37 s.setLongName("test")
38 self.assertTrue(s.getLongName() == "test", "wrong reset long name")
39 self.assertTrue(abs( s(3.)-13.) <= self.TOL*13. , " s(3.) wrong.")
40 self.assertTrue(abs( 3.*s-13.) <= self.TOL*13. , " 13.s wrong.")
41 self.assertTrue(abs( 10.*s-41.) <= self.TOL*41. , " 10.s wrong.")
42 self.assertTrue(abs( 41./s-10.) <= self.TOL*10. , " 10/s wrong.")
43 self.assertTrue(abs( 13./s-3.) <= self.TOL*3. , " 13/s wrong.")
44
45 x=Unit("x","X",10.,2.)
46 y=Unit("y","Y",0.,4.)
47 z=Unit("z","Z",0.,0.5)
48 p_m=x*s
49 self.assertTrue(p_m.getName() == "xt", "wrong p_m name")
50 self.assertTrue(p_m.getLongName() == "X*test", "wrong p_m long name")
51 self.assertTrue(abs(p_m(0.)-12.) <= self.TOL*12 , " p_m(0) wrong.")
52 self.assertTrue(abs(p_m(1.)-20.) <= self.TOL*20 , " p_m(1) wrong.")
53
54 p_d=y/z
55 self.assertTrue(p_d.getName() == "y/z", "wrong p_d name")
56 self.assertTrue(p_d.getLongName() == "Y/Z", "wrong p_d long name")
57 self.assertTrue(abs(p_d(1.)-8.) <= self.TOL*8. , " p_d(0) wrong.")
58 self.assertTrue(abs(p_d(2.)-16.) <= self.TOL*16. , " p_d(1) wrong.")
59
60 p_p=y**3
61 self.assertTrue(p_p.getName() == "y^3", "p_p mult name")
62 self.assertTrue(p_p.getLongName() == "Y^3", "wrong p_p long name")
63 self.assertTrue(abs(p_p(1.)-64.) <= self.TOL*64. , " p_p(0) wrong.")
64 self.assertTrue(abs(p_p(.5)-32) <= self.TOL*32. , " p_p(1) wrong.")
65
66
67 x=Unit("x","X",0.,2.)
68 y=Unit("y","Y",0.,4.)
69 z=Unit("z","Z",0.,0.5)
70
71 self.assertTrue(((x*x)).getName() == "xx", "wrong name")
72 self.assertTrue((x*(x*z)).getName() == "xxz", "wrong name")
73 self.assertTrue((x*(x/z)).getName() == "xx/z", "wrong name")
74 self.assertTrue((x*(y**3)).getName() == "x y^3", "wrong name")
75
76 self.assertTrue(((x*z)*x).getName() == "xzx", "wrong name")
77 self.assertTrue(((x*z)*(x*z)).getName() == "xzxz", "wrong name")
78 self.assertTrue(((x*z)*(x/z)).getName() == "xzx/z", "wrong name")
79 self.assertTrue(((x*z)*(y**3)).getName() == "xz y^3", "wrong name")
80
81 self.assertTrue(((x/z)*x).getName() == "x/z x", "wrong name")
82 self.assertTrue(((x/z)*(x*z)).getName() == "x/z xz", "wrong name")
83 self.assertTrue(((x/z)*(x/z)).getName() == "x/z x/z", "wrong name")
84 self.assertTrue(((x/z)*(y**3)).getName() == "x/z y^3", "wrong name")
85
86 self.assertTrue(((y**3)*x).getName() == "y^3 x", "wrong name")
87 self.assertTrue(((y**3)*(x*z)).getName() == "y^3 xz", "wrong name")
88 self.assertTrue(((y**3)*(x/z)).getName() == "y^3 x/z", "wrong name")
89 self.assertTrue(((y**3)*(y**3)).getName() == "y^3 y^3", "wrong name")
90
91 self.assertTrue((x/x).getName() == "x/x", "wrong name")
92 self.assertTrue((x/(x*z)).getName() == "x/(xz)", "wrong name")
93 self.assertTrue((x/(x/z)).getName() == "x/(x/z)", "wrong name")
94 self.assertTrue((x/(y**3)).getName() == "x/y^3", "wrong name")
95
96 self.assertTrue(((x*z)/x).getName() == "xz/x", "wrong name")
97 self.assertTrue(((x*z)/(x*z)).getName() == "xz/(xz)", "wrong name")
98 self.assertTrue(((x*z)/(x/z)).getName() == "xz/(x/z)", "wrong name")
99 self.assertTrue(((x*z)/(y**3)).getName() == "xz/y^3", "wrong name")
100
101 self.assertTrue(((x/z)/x).getName() == "x/z/x", "wrong name")
102 self.assertTrue(((x/z)/(x*z)).getName() == "x/z/(xz)", "wrong name")
103 self.assertTrue(((x/z)/(x/z)).getName() == "x/z/(x/z)", "wrong name")
104 self.assertTrue(((x/z)/(y**3)).getName() == "x/z/y^3", "wrong name")
105
106 self.assertTrue(((y**3)/x).getName() == "y^3/x", "wrong name")
107 self.assertTrue(((y**3)/(x*z)).getName() == "y^3/(xz)", "wrong name")
108 self.assertTrue(((y**3)/(x/z)).getName() == "y^3/(x/z)", "wrong name")
109 self.assertTrue(((y**3)/(y**3)).getName() == "y^3/y^3", "wrong name")
110
111 self.assertTrue((x**2).getName() == "x^2", "wrong name")
112 self.assertTrue(((x*z)**2).getName() == "(xz)^2", "wrong name")
113 self.assertTrue(((x/z)**2).getName() == "(x/z)^2", "wrong name")
114 self.assertTrue(((y**3)**2).getName() == "(y^3)^2", "wrong name")
115
116 self.assertTrue(((x*x)).getLongName() == "X*X", "wrong long name")
117 self.assertTrue((x*(x*z)).getLongName() == "X*X*Z", "wrong long name")
118 self.assertTrue((x*(x/z)).getLongName() == "X*X/Z", "wrong long name")
119 self.assertTrue((x*(y**3)).getLongName() == "X*Y^3", "wrong long name")
120
121 self.assertTrue(((x*z)*x).getLongName() == "X*Z*X", "wrong long name")
122 self.assertTrue(((x*z)*(x*z)).getLongName() == "X*Z*X*Z", "wrong long name")
123 self.assertTrue(((x*z)*(x/z)).getLongName() == "X*Z*X/Z", "wrong long name")
124 self.assertTrue(((x*z)*(y**3)).getLongName() == "X*Z*Y^3", "wrong long name")
125
126 self.assertTrue(((x/z)*x).getLongName() == "X/Z*X", "wrong long name")
127 self.assertTrue(((x/z)*(x*z)).getLongName() == "X/Z*X*Z", "wrong long name")
128 self.assertTrue(((x/z)*(x/z)).getLongName() == "X/Z*X/Z", "wrong long name")
129 self.assertTrue(((x/z)*(y**3)).getLongName() == "X/Z*Y^3", "wrong long name")
130
131 self.assertTrue(((y**3)*x).getLongName() == "Y^3*X", "wrong long name")
132 self.assertTrue(((y**3)*(x*z)).getLongName() == "Y^3*X*Z", "wrong long name")
133 self.assertTrue(((y**3)*(x/z)).getLongName() == "Y^3*X/Z", "wrong long name")
134 self.assertTrue(((y**3)*(y**3)).getLongName() == "Y^3*Y^3", "wrong long name")
135
136 self.assertTrue((x/x).getLongName() == "X/X", "wrong long name")
137 self.assertTrue((x/(x*z)).getLongName() == "X/(X*Z)", "wrong long name")
138 self.assertTrue((x/(x/z)).getLongName() == "X/(X/Z)", "wrong long name")
139 self.assertTrue((x/(y**3)).getLongName() == "X/Y^3", "wrong long name")
140
141 self.assertTrue(((x*z)/x).getLongName() == "X*Z/X", "wrong long name")
142 self.assertTrue(((x*z)/(x*z)).getLongName() == "X*Z/(X*Z)", "wrong long name")
143 self.assertTrue(((x*z)/(x/z)).getLongName() == "X*Z/(X/Z)", "wrong long name")
144 self.assertTrue(((x*z)/(y**3)).getLongName() == "X*Z/Y^3", "wrong long name")
145
146 self.assertTrue(((x/z)/x).getLongName() == "X/Z/X", "wrong long name")
147 self.assertTrue(((x/z)/(x*z)).getLongName() == "X/Z/(X*Z)", "wrong long name")
148 self.assertTrue(((x/z)/(x/z)).getLongName() == "X/Z/(X/Z)", "wrong long name")
149 self.assertTrue(((x/z)/(y**3)).getLongName() == "X/Z/Y^3", "wrong long name")
150
151 self.assertTrue(((y**3)/x).getLongName() == "Y^3/X", "wrong long name")
152 self.assertTrue(((y**3)/(x*z)).getLongName() == "Y^3/(X*Z)", "wrong long name")
153 self.assertTrue(((y**3)/(x/z)).getLongName() == "Y^3/(X/Z)", "wrong long name")
154 self.assertTrue(((y**3)/(y**3)).getLongName() == "Y^3/Y^3", "wrong long name")
155
156 self.assertTrue((x**2).getLongName() == "X^2", "wrong long name")
157 self.assertTrue(((x*z)**2).getLongName() == "(X*Z)^2", "wrong long name")
158 self.assertTrue(((x/z)**2).getLongName() == "(X/Z)^2", "wrong long name")
159 self.assertTrue(((y**3)**2).getLongName() == "(Y^3)^2", "wrong long name")
160
161 def testPrefix(self):
162
163
164 self.assertTrue(Yotta.getName() == "Y","Yotta name wrong")
165 self.assertTrue(Zetta.getName() == "Z","Zetta name wrong")
166 self.assertTrue(Exa.getName() == "E","Exa name wrong")
167 self.assertTrue(Peta.getName() == "P","Peta name wrong")
168 self.assertTrue(Tera.getName() == "T","Tera name wrong")
169 self.assertTrue(Giga.getName() == "G","Giga name wrong")
170 self.assertTrue(Mega.getName() == "M","Mega name wrong")
171 self.assertTrue(Kilo.getName() == "k","Kilo name wrong")
172 self.assertTrue(Hecto.getName() == "h","Hecto name wrong")
173 self.assertTrue(Deca.getName() == "da","Deca name wrong")
174 self.assertTrue(Deci.getName() == "d","Deci name wrong")
175 self.assertTrue(Centi.getName() == "c","Centi name wrong")
176 self.assertTrue(Milli.getName() == "m","Milli name wrong")
177 self.assertTrue(Micro.getName() == "mu","Micro name wrong")
178 self.assertTrue(Nano.getName() == "n","Nano name wrong")
179 self.assertTrue(Pico.getName() == "p","Pico name wrong")
180 self.assertTrue(Femto.getName() == "f","Femto name wrong")
181 self.assertTrue(Atto.getName() == "a","Atto name wrong")
182 self.assertTrue(Zepto.getName() == "z","Zepto name wrong")
183 self.assertTrue(Yocto.getName() == "y","Yocto name wrong")
184
185 self.assertTrue(Yotta.getLongName() == "Yotta","wrong long name")
186 self.assertTrue(Zetta.getLongName() == "Zetta","wrong long name")
187 self.assertTrue(Exa.getLongName() == "Exa","wrong long name")
188 self.assertTrue(Peta.getLongName() == "Peta","wrong long name")
189 self.assertTrue(Tera.getLongName() == "Tera","wrong long name")
190 self.assertTrue(Giga.getLongName() == "Giga","wrong long name")
191 self.assertTrue(Mega.getLongName() == "Mega","wrong long name")
192 self.assertTrue(Kilo.getLongName() == "Kilo","wrong long name")
193 self.assertTrue(Hecto.getLongName() == "Hecto","wrong long name")
194 self.assertTrue(Deca.getLongName() == "Deca","wrong long name")
195 self.assertTrue(Deci.getLongName() == "Deci","wrong long name")
196 self.assertTrue(Centi.getLongName() == "Centi","wrong long name")
197 self.assertTrue(Milli.getLongName() == "Milli","wrong long name")
198 self.assertTrue(Micro.getLongName() == "Micro","wrong long name")
199 self.assertTrue(Nano.getLongName() == "Nano","wrong long name")
200 self.assertTrue(Pico.getLongName() == "Pico","wrong long name")
201 self.assertTrue(Femto.getLongName() == "Femto","wrong long name")
202 self.assertTrue(Atto.getLongName() == "Atto","wrong long name")
203 self.assertTrue(Zepto.getLongName() == "Zepto","wrong long name")
204 self.assertTrue(Yocto.getLongName() == "Yocto","wrong long name")
205
206 self.assertTrue(abs(Yotta(1.)/1.e24 -1.) <= self.TOL , "wrong b value")
207 self.assertTrue(abs(Zetta(1.)/1.e21 -1.) <= self.TOL , "wrong b value")
208 self.assertTrue(abs(Exa(1.)/1.e18 -1.) <= self.TOL , "wrong b value")
209 self.assertTrue(abs(Peta(1.)/1.e15 -1.) <= self.TOL , "wrong b value")
210 self.assertTrue(abs(Tera(1.)/1.e12 -1.) <= self.TOL , "wrong b value")
211 self.assertTrue(abs(Giga(1.)/1.e9 -1.) <= self.TOL , "wrong b value")
212 self.assertTrue(abs(Mega(1.)/1.e6 -1.) <= self.TOL , "wrong b value")
213 self.assertTrue(abs(Kilo(1.)/1.e3 -1.) <= self.TOL , "wrong b value")
214 self.assertTrue(abs(Hecto(1.)/1.e2 -1.) <= self.TOL , "wrong b value")
215 self.assertTrue(abs(Deca(1.)/1.e1 -1.) <= self.TOL , "wrong b value")
216 self.assertTrue(abs(Deci(1.)/1.e-1 -1.) <= self.TOL , "wrong b value")
217 self.assertTrue(abs(Centi(1.)/1.e-2 -1.) <= self.TOL , "wrong b value")
218 self.assertTrue(abs(Milli(1.)/1.e-3 -1.) <= self.TOL , "wrong b value")
219 self.assertTrue(abs(Micro(1.)/1.e-6 -1.) <= self.TOL , "wrong b value")
220 self.assertTrue(abs(Nano(1.)/1.e-9 -1.) <= self.TOL , "wrong b value")
221 self.assertTrue(abs(Pico(1.)/1.e-12 -1.) <= self.TOL , "wrong b value")
222 self.assertTrue(abs(Femto(1.)/1.e-15 -1.) <= self.TOL , "wrong b value")
223 self.assertTrue(abs(Atto(1.)/1.e-18 -1.) <= self.TOL , "wrong b value")
224 self.assertTrue(abs(Zepto(1.)/1.e-21 -1.) <= self.TOL , "wrong b value")
225 self.assertTrue(abs(Yocto(1.)/1.e-24 -1.) <= self.TOL , "wrong b value")
226
227 self.assertTrue(abs( Yotta(1.) * Yocto(1.) - 1.) <= self.TOL , " Yotta or Yocto wrong.")
228 self.assertTrue(Yotta(0.) == 0. , " Yotta a value wrong.")
229 self.assertTrue(Yocto(0.) == 0. , " Yocto a value wrong.")
230 self.assertTrue(abs( Zetta(1.) * Zepto(1.) - 1.) <= self.TOL , " Zetta or Zepto wrong.")
231 self.assertTrue(Zetta(0.) == 0. , " Zetta a value wrong.")
232 self.assertTrue(Zepto(0.) == 0. , " Zepto a value wrong.")
233 self.assertTrue(abs( Exa(1.) * Atto(1.) - 1.) <= self.TOL , " Exa or Atto wrong.")
234 self.assertTrue(Exa(0.) == 0. , " Exa a value wrong.")
235 self.assertTrue(Atto(0.) == 0. , " Atto a value wrong.")
236 self.assertTrue(abs( Peta(1.) *Femto(1.) - 1.) <= self.TOL , " Peta or Femto wrong.")
237 self.assertTrue(Peta(0.) == 0. , " Peta a value wrong.")
238 self.assertTrue(Femto(0.) == 0. , " Femto a value wrong.")
239 self.assertTrue(abs( Tera(1.) * Pico(1.) - 1.) <= self.TOL , " Tera or Pico wrong.")
240 self.assertTrue(Tera(0.) == 0. , " Tera a value wrong.")
241 self.assertTrue(Pico(0.) == 0. , " Pico a value wrong.")
242 self.assertTrue(abs( Giga(1.) * Nano(1.) - 1.) <= self.TOL , " Giga or Nano wrong.")
243 self.assertTrue(Giga(0.) == 0. , " Giga a value wrong.")
244 self.assertTrue(Nano(0.) == 0. , " Nano a value wrong.")
245 self.assertTrue(abs( Mega(1.) *Micro(1.) - 1.) <= self.TOL , " Mega or Micro wrong.")
246 self.assertTrue(Mega(0.) == 0. , "Mega a value wrong.")
247 self.assertTrue(Micro(0.) == 0. , " Micro a value wrong.")
248 self.assertTrue(abs( Kilo(1.) * Milli(1.) - 1.) <= self.TOL , "Kilo or Milli wrong.")
249 self.assertTrue( Kilo(0.) == 0. , "Kilo a value wrong.")
250 self.assertTrue(Milli(0.) == 0. , "Milli a value wrong.")
251 self.assertTrue(abs( Hecto(1.) * Centi(1.)- 1.) <= self.TOL , " Hecto or Centi wrong.")
252 self.assertTrue(Hecto(0.) == 0., " Hecto a value wrong.")
253 self.assertTrue(Centi(0.)== 0. , " Centi a value wrong.")
254 self.assertTrue(abs( Deca(1.) * Deci(1.) - 1.) <= self.TOL , "Deca or Deci wrong.")
255 self.assertTrue(Deca(0.) == 0. , "Deca a value wrong.")
256 self.assertTrue(Deci(0.) == 0. , "Deci a value wrong.")
257 def testLength(self):
258 self.assertTrue(m.getName() == "m", "meter name wrong.")
259 self.assertTrue(m.getLongName() == "meter", "meter long name wrong.")
260 self.assertTrue(abs( m(1.) - 1.) <= self.TOL , " meter wrong.")
261 self.assertTrue(abs( km(1.) - 1000.) <= self.TOL*1000. , " km wrong.")
262 self.assertTrue(abs( cm(1.) - 1./100.) <= self.TOL/100. , " cm wrong.")
263 self.assertTrue(abs( mm(1.) - 1./1000.) <= self.TOL/1000. , " mm wrong.")
264 self.assertTrue(m(0.) == 0., " meter wrong.")
265 self.assertTrue(km(0.) == 0., " km wrong.")
266 self.assertTrue(cm(0.) == 0. , " cm wrong.")
267 self.assertTrue(mm(0.) ==0.," mm wrong.")
268 def testTime(self):
269 self.assertTrue(sec.getName() == "sec" , "sec name wrong")
270 self.assertTrue(sec.getLongName() == "second" , "sec long name wrong")
271 self.assertTrue(minute.getName() == "min" , "minute name wrong")
272 self.assertTrue(minute.getLongName() == "minute" , "minute long name wrong")
273 self.assertTrue(h.getName() == "h" , "hour name wrong")
274 self.assertTrue(h.getLongName() == "hour" , "hour long name wrong")
275 self.assertTrue(day.getName() == "d" , "day name wrong")
276 self.assertTrue(day.getLongName() == "day" , "day long name wrong")
277 self.assertTrue(yr.getName() == "yr" , "year name wrong")
278 self.assertTrue(yr.getLongName() == "year" , "year long name wrong")
279
280 self.assertTrue(abs( sec(1.) - 1.) <= self.TOL , " second wrong.")
281 self.assertTrue(abs( minute(1.) - 60.) <= self.TOL*60 , " minute wrong.")
282 self.assertTrue(abs( h(1.) - 3600) <= self.TOL*3600., " h wrong.")
283 self.assertTrue(abs( day(1.) - 86400.) <= self.TOL*86400 , " day wrong.")
284 self.assertTrue(abs( yr(1.) - 31556952) <= self.TOL*31556952 , " yr wrong.")
285 self.assertTrue(abs( Myr(1.) - 31556952.e6) <= self.TOL*31556952.e6 , " Myr wrong.")
286 self.assertTrue(abs( Gyr(1.) - 31556952.e9) <= self.TOL*31556952.e9 , " Gyr wrong.")
287
288 self.assertTrue(sec(0.) == 0. , " second wrong.")
289 self.assertTrue(minute(0.) == 0. , " minute wrong.")
290 self.assertTrue(h(0.) == 0., " h wrong.")
291 self.assertTrue(day(0.) == 0. , " day wrong.")
292 self.assertTrue(yr(0.) == 0. , " yr wrong.")
293 self.assertTrue(Myr(0.) == 0. , " Myr wrong.")
294 self.assertTrue(Gyr(0.) == 0., " Gyr wrong.")
295 def testMass(self):
296 self.assertTrue(kg.getName() == "kg" , " kg wrong.")
297 self.assertTrue(lb.getName() == "lb" , " lb wrong.")
298 self.assertTrue(kg.getLongName() == "kg" , " kg wrong.")
299 self.assertTrue(lb.getLongName() == "pound" , " lb wrong.")
300
301 self.assertTrue(abs( gram(1.) - 1./1000.) <= self.TOL/1000. , " gram wrong.")
302 self.assertTrue(abs( kg(1.) - 1.) <= self.TOL , " kg wrong.")
303 self.assertTrue(abs( ton(1.) - 1.e3) <= self.TOL*1.e3 , " ton wrong.")
304 self.assertTrue(abs( lb(1.) - 0.45359237) <= self.TOL , " lb wrong.")
305
306 self.assertTrue(gram(0.) == 0. , " gram wrong.")
307 self.assertTrue(kg(0.) == 0. , " kg wrong.")
308 self.assertTrue(ton(0.) == 0. , " ton wrong.")
309 self.assertTrue(lb(0.) == 0. , " lb wrong.")
310
311 def testCurrent(self):
312 self.assertTrue(A.getName() == "A" , " A wrong.")
313 self.assertTrue(A.getLongName() == "Ampere" , " A wrong.")
314 self.assertTrue(A(0.) == 0. , " A wrong.")
315 self.assertTrue(abs( A(1.)- 1.) <= self.TOL , " A wrong.")
316 def testFrequency(self):
317 self.assertTrue(Hz(0.) == 0. , " Hz wrong.")
318 self.assertTrue(abs( Hz(1)- 1.) <= self.TOL , " Hz wrong.")
319
320 def testForce(self):
321 self.assertTrue(N.getName() == "N" , "N wrong.")
322 self.assertTrue(N.getLongName() == "Newton" , " N wrong.")
323 self.assertTrue(N(0.) == 0. , " N wrong.")
324 self.assertTrue(abs( N(1)- 1.) <= self.TOL , " N wrong.")
325 def testPressure(self):
326 self.assertTrue(Pa.getName() == "Pa" , " Pa wrong.")
327 self.assertTrue(Pa.getLongName() == "Pascal" , " Pa wrong.")
328 self.assertTrue(Pa(0.) == 0. , " Pa wrong.")
329 self.assertTrue(abs( Pa(1)- 1.) <= self.TOL , " Pa wrong.")
330
331 self.assertTrue(atm.getName() == "atm" , " atm wrong.")
332 self.assertTrue(atm.getLongName() == "atmosphere" , " atm wrong.")
333 self.assertTrue(atm(0.) == 0. , " atm wrong.")
334 self.assertTrue(abs( atm(1)- 101325.024) <= self.TOL*101325.024 , " atm wrong.")
335
336 def testEnegry(self):
337 self.assertTrue(J.getName() == "J" , " J wrong.")
338 self.assertTrue(J.getLongName() == "Joule" , " J wrong.")
339 self.assertTrue(J(0.) == 0. , " J wrong.")
340 self.assertTrue(abs( J(1)- 1.) <= self.TOL , " J wrong.")
341
342 def testPower(self):
343 self.assertTrue(W.getName() == "W" , " W wrong.")
344 self.assertTrue(W.getLongName() == "Watt" , " W wrong.")
345 self.assertTrue(W(0.) == 0. , " W wrong.")
346 self.assertTrue(abs( W(1)- 1.) <= self.TOL , " W wrong.")
347
348 def testPotential(self):
349 self.assertTrue(V.getName() == "V" , " V wrong.")
350 self.assertTrue(V.getLongName() == "Volt" , " V wrong.")
351 self.assertTrue(V(0.) == 0. , " V wrong.")
352 self.assertTrue(abs( V(1)- 1.) <= self.TOL , " V wrong.")
353
354 def testCharge(self):
355 self.assertTrue(C.getName() == "C" , " C wrong.")
356 self.assertTrue(C.getLongName() == "Coulomb" , " C wrong.")
357 self.assertTrue(C(0.) == 0. , " C wrong.")
358 self.assertTrue(abs( C(1)- 1.) <= self.TOL , " C wrong.")
359
360 def testResistance(self):
361 self.assertTrue(Ohm.getName() == "Ohm" , " Ohm wrong.")
362 self.assertTrue(Ohm.getLongName() == "Ohm" , " Ohm wrong.")
363 self.assertTrue(Ohm(0.) == 0. , " Ohm wrong.")
364 self.assertTrue(abs( Ohm(1)- 1.) <= self.TOL , " Ohm wrong.")
365 def testTemperature(self):
366 self.assertTrue(K.getName() == "K" , " Kelvin wrong.")
367 self.assertTrue(K.getLongName() == "Kelvin" , " Kelvin wrong.")
368 self.assertTrue(K(0.) == 0. , " Kelvin wrong.")
369 self.assertTrue(abs( K(1.)- 1.) <= self.TOL , " Kelvin wrong.")
370
371 self.assertTrue(Celsius.getName() == "C" , " Celsius wrong.")
372 self.assertTrue(Celsius.getLongName() == "Celsius" , " Celsius wrong.")
373 self.assertTrue(abs(Celsius(20.) - 293.15) <= self.TOL*293.15 , " Celsius 20 conversion wrong.")
374 self.assertTrue(abs(Celsius(-2.)- 271.15) <= self.TOL*271.15 , " Celsius conversion wrong.")
375 self.assertTrue(abs(Celsius(100.)- 373.15) <= self.TOL*373.15 , " Celsius conversion wrong.")
376
377 self.assertTrue(Fahrenheit.getName() == "F" , " Fahrenheit wrong.")
378 self.assertTrue(Fahrenheit.getLongName() == "Fahrenheit" , " Fahrenheit wrong.")
379 self.assertTrue(abs( Fahrenheit(0.)- 255.3722222) <= 1.e-8*255.3722222, " Fahrenheit wrong.")
380 self.assertTrue(abs( Fahrenheit(20.)- 266.4833333) <= 1.e-8*266.4833333 , " Fahrenheit wrong.")
381 self.assertTrue(abs( Fahrenheit(100.)- 310.9277778 ) <= 1.e-8 * 310.9277778 , " Fahrenheit wrong.")
382 self.assertTrue(abs( Fahrenheit(-1.)- 254.8166667) <= 1.e-8 *254.8166667, "Fahrenheit wrong.")
383
384
385 def testEarth(self):
386 R=6367444.65
387 self.assertTrue(abs( R_Earth_equator-6378137) <= self.TOL*R , " R_Earth_equator wrong.")
388 self.assertTrue(abs( R_Earth_poles-6356752.3) <= self.TOL*R , " R_Earth_poles wrong.")
389 self.assertTrue(abs( R_Earth-R) <= self.TOL*R , "R_Earth wrong.")
390 def testVlight(self):
391 self.assertTrue(abs(v_light - 299792458.) <= self.TOL*299792458. , " speed of light is wrong.")
392
393 if __name__ == "__main__":
394 suite = unittest.TestSuite()
395 suite.addTest(unittest.makeSuite(UnitsSITestCase))
396 s=unittest.TextTestRunner(verbosity=2).run(suite)
397 if not s.wasSuccessful(): sys.exit(1)

  ViewVC Help
Powered by ViewVC 1.1.26