/[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 82 - (hide annotations)
Tue Oct 26 06:53:54 2004 UTC (16 years, 11 months ago) by jgs
File MIME type: text/x-python
File size: 3562 byte(s)
Initial revision

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26