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

Contents of /trunk/escript/test/python/newEscriptTests.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (14 years ago) by jgs
File MIME type: text/x-python
File size: 3466 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26