1 |
""" |
2 |
|
3 |
Random interactive escript/Data tests. |
4 |
|
5 |
Version $Id$ |
6 |
|
7 |
""" |
8 |
|
9 |
import os |
10 |
import sys |
11 |
import unittest |
12 |
import math |
13 |
|
14 |
from esys.escript import * |
15 |
from esys import bruce |
16 |
|
17 |
arglist = [ \ |
18 |
3.0, \ |
19 |
[3,4], \ |
20 |
[[1,2],[3,4]], \ |
21 |
[[15,8],[12,8]], \ |
22 |
[[[15,8],[12,8]],[[-9,9],[13,8]]] \ |
23 |
] |
24 |
|
25 |
# |
26 |
# ============================================================== |
27 |
|
28 |
class escriptTestCase(unittest.TestCase): |
29 |
|
30 |
def setUp(self): |
31 |
self.msh=bruce.Rectangle() |
32 |
|
33 |
def prepareArg(self,val,ex,wh): |
34 |
if ex=="Expanded": |
35 |
exx=True |
36 |
else: |
37 |
exx=False |
38 |
out=Data(val,what=wh,expand=exx) |
39 |
return out |
40 |
|
41 |
def testAlina1(self): |
42 |
P1 = 10.0 |
43 |
assert log(P1) == math.log10(10.0) |
44 |
assert ln(P1) == math.log(10.0,math.e) |
45 |
|
46 |
def testAlina2(self): |
47 |
P = 10.0*Scalar(1.0, ContinuousFunction(self.msh)) |
48 |
assert log(P).convertToNumArray()[0] == math.log10(10.0) |
49 |
assert ln(P).convertToNumArray()[0] == math.log(10.0,math.e) |
50 |
|
51 |
def testLog(self): |
52 |
for wh in [ContinuousFunction(self.msh),Function(self.msh)]: |
53 |
for ex in ["Constant","Expanded"]: |
54 |
for a in arglist: |
55 |
#print "\n", ex, a, "==>" |
56 |
arg=self.prepareArg(a,ex,wh) |
57 |
#print "\nlog" |
58 |
result = arg.log() |
59 |
|
60 |
def testLn(self): |
61 |
for wh in [ContinuousFunction(self.msh),Function(self.msh)]: |
62 |
for ex in ["Constant","Expanded"]: |
63 |
for a in arglist: |
64 |
#print "\n", ex, a, "==>" |
65 |
arg=self.prepareArg(a,ex,wh) |
66 |
#print "\nln" |
67 |
result = arg.ln() |
68 |
|
69 |
if __name__ == '__main__': |
70 |
suite=unittest.TestSuite() |
71 |
suite.addTest(unittest.makeSuite(escriptTestCase)) |
72 |
unittest.TextTestRunner(verbosity=2).run(suite) |
73 |
|
74 |
sys.exit(0) |
75 |
# end |