/[escript]/trunk/esys2/escript/test/python/newEscriptTests.py
ViewVC logotype

Annotation of /trunk/esys2/escript/test/python/newEscriptTests.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 3 months ago) by jgs
File MIME type: text/x-python
File size: 3490 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

1 jgs 82 import sys
2     import unittest
3 jgs 104
4 jgs 82 import numarray
5    
6 jgs 149 from esys.escript import *
7     from esys import finley
8 jgs 104
9 jgs 82 class DataTestCase(unittest.TestCase):
10 jgs 147
11 jgs 82 def powTest(self):
12     a=escript.Data([1,2],3,3)
13     print a
14     a=a**3
15     print a
16 jgs 147
17 jgs 82 def dataOperationTest(self):
18     #
19     # Create expanded data with a vector at each node
20     myFuncSpac=escript.FunctionSpace()
21     myVector=numarray.array([[1,2],[3,4]])
22 jgs 147 myData=escript.Data(myVector,myFuncSpac,True)
23 jgs 82 myData2=myData
24     #
25     # Test operator+
26     myData3=myData+myData2
27     print myData3
28 jgs 147
29 jgs 82 def binaryOperationTest(self):
30 jgs 147 a=escript.Data([1,2])
31 jgs 82 print a
32     a-=1
33     print a
34    
35     def unaryOperationTest(self):
36 jgs 147 constData=escript.Data([1,2])
37 jgs 149 result=sin(constData)
38 jgs 82 print result
39 jgs 147
40 jgs 82 def dataExpansionTest(self):
41 jgs 147 constData=escript.Data([1,2])
42 jgs 82 print constData
43     constData.expand()
44     print constData
45     #
46     # check expansion occurs automaticaly when needed
47 jgs 147 constData=escript.Data(1)
48 jgs 82 myFuncSpac=escript.FunctionSpace()
49 jgs 147 expandedData=escript.Data(2,myFuncSpac,True)
50 jgs 82 #
51     # this operation should cause automatic expansion
52     try:
53     resultData=constData+expandedData
54     assert (False,'Failed shape mismatch exception test.')
55     except Exception, e:
56     print e
57     print 'Passed shape mismatch exception test.'
58     #
59     # do the expansion test
60 jgs 147 expandedData=escript.Data(2,myFuncSpac,True)
61 jgs 82 resultData=constData+expandedData
62     print resultData
63 jgs 147
64 jgs 82 def runTest(self):
65     self.binaryOperationTest()
66 jgs 147 self.unaryOperationTest()
67     self.dataExpansionTest()
68     self.dataOperationTest()
69 jgs 82 #
70     # Create constant data
71     myData=escript.Data(1)
72     myFuncSpac=escript.FunctionSpace()
73     #
74     # Create expanded data with a vector at each node
75     a=numarray.array([1,2])
76 jgs 147 myData2=escript.Data(a,myFuncSpac,True)
77 jgs 82 try:
78     myData2+='fred'
79     assert(False, 'Failed illegal argument to operator+= test.')
80     except Exception, e:
81     print e
82     print 'Passed illegal argument to operator+= test.'
83     #
84     # Test adding a scalar to a 1 dimensional Data
85 jgs 147 myData3=escript.Data(a,myFuncSpac,True)
86 jgs 82 myData3+=2.0
87     print myData2
88     myData2+=2.0
89     print myData2
90     myData+=1
91     try:
92     myData+=myData2
93     assert(False, 'Failed shape mismatch on += exception test.')
94     except Exception, e:
95     print e
96     print 'Passed shape mismatch on += exception test.'
97     try:
98     myData3=myData+myData2
99     assert(False, 'Failed currently illegal operation test.')
100     except Exception, e:
101     print e
102     print 'Passed currently illegal operation test.'
103 jgs 147 myData3=escript.Data(2.1,myFuncSpac,True)
104 jgs 82 print myData3
105     myData3+=1.0
106     print myData3
107     try:
108     myData3+=a
109     assert (False, 'Failed shape mismatch exception test.')
110     except Exception, e:
111     print e
112     print 'Passed shape mismatch exception test.'
113     newData=myData3+1.0
114     print newData
115     print myData3
116     try:
117 jgs 147 myData4=escript.Data(3.2,myFuncSpac,True)
118 jgs 82 assert (False, 'Failed 0 size exception test.')
119     except Exception, e:
120     print e
121     print 'Passed 0 size exception Test'
122    
123 jgs 147 myData5=escript.Data(a,myFuncSpac,True)
124 jgs 82 myData5=myData5+3.1
125     print myData5
126    
127     dataTestCase=DataTestCase()
128     dataTestCase.runTest()
129    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26