/[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 104 - (hide annotations)
Fri Dec 17 07:43:12 2004 UTC (16 years, 9 months ago) by jgs
File MIME type: text/x-python
File size: 3546 byte(s)
*** empty log message ***

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26