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 |
if ex=="Tagged": |
40 |
out.tag() |
41 |
return out |
42 |
|
43 |
def testAlina1(self): |
44 |
P1 = 10.0 |
45 |
assert log10(P1) == math.log10(10.0) |
46 |
assert log(P1) == math.log(10.0,math.e) |
47 |
|
48 |
def testAlina2(self): |
49 |
P = 10.0*Scalar(1.0, ContinuousFunction(self.msh)) |
50 |
assert log10(P).convertToNumArray()[0] == math.log10(10.0) |
51 |
assert log(P).convertToNumArray()[0] == math.log(10.0,math.e) |
52 |
|
53 |
def testLog(self): |
54 |
for wh in [ContinuousFunction(self.msh),Function(self.msh)]: |
55 |
for ex in ["Constant","Tagged","Expanded"]: |
56 |
for a in arglist: |
57 |
#print "\n", ex, a, "==>" |
58 |
arg=self.prepareArg(a,ex,wh) |
59 |
#print "\nlog" |
60 |
result = arg._log10() |
61 |
|
62 |
def testLn(self): |
63 |
for wh in [ContinuousFunction(self.msh),Function(self.msh)]: |
64 |
for ex in ["Constant","Tagged","Expanded"]: |
65 |
for a in arglist: |
66 |
#print "\n", ex, a, "==>" |
67 |
arg=self.prepareArg(a,ex,wh) |
68 |
#print "\nln" |
69 |
result = arg._log() |
70 |
|
71 |
def testEmptyOp(self): |
72 |
emptyData=Data() |
73 |
emptyData._sin() |
74 |
emptyData2=Data() |
75 |
emptyData3=emptyData+emptyData2 |
76 |
|
77 |
if __name__ == '__main__': |
78 |
suite=unittest.TestSuite() |
79 |
suite.addTest(unittest.makeSuite(escriptTestCase)) |
80 |
unittest.TextTestRunner(verbosity=2).run(suite) |
81 |
|
82 |
sys.exit(0) |
83 |
# end |