/[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 147 - (show annotations)
Fri Aug 12 01:45:47 2005 UTC (14 years, 5 months ago) by jgs
Original Path: trunk/esys2/escript/test/python/newEscriptTests.py
File MIME type: text/x-python
File size: 3503 byte(s)
erge of development branch dev-02 back to main trunk on 2005-08-12

1 import sys
2 import unittest
3
4 import numarray
5
6 from escript.escript import *
7 from finley import finley
8
9 class DataTestCase(unittest.TestCase):
10
11 def powTest(self):
12 a=escript.Data([1,2],3,3)
13 print a
14 a=a**3
15 print a
16
17 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 myData=escript.Data(myVector,myFuncSpac,True)
23 myData2=myData
24 #
25 # Test operator+
26 myData3=myData+myData2
27 print myData3
28
29 def binaryOperationTest(self):
30 a=escript.Data([1,2])
31 print a
32 a-=1
33 print a
34
35 def unaryOperationTest(self):
36 constData=escript.Data([1,2])
37 result=escript.sin(constData)
38 print result
39
40 def dataExpansionTest(self):
41 constData=escript.Data([1,2])
42 print constData
43 constData.expand()
44 print constData
45 #
46 # check expansion occurs automaticaly when needed
47 constData=escript.Data(1)
48 myFuncSpac=escript.FunctionSpace()
49 expandedData=escript.Data(2,myFuncSpac,True)
50 #
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 expandedData=escript.Data(2,myFuncSpac,True)
61 resultData=constData+expandedData
62 print resultData
63
64 def runTest(self):
65 self.binaryOperationTest()
66 self.unaryOperationTest()
67 self.dataExpansionTest()
68 self.dataOperationTest()
69 #
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 myData2=escript.Data(a,myFuncSpac,True)
77 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 myData3=escript.Data(a,myFuncSpac,True)
86 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 myData3=escript.Data(2.1,myFuncSpac,True)
104 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 myData4=escript.Data(3.2,myFuncSpac,True)
118 assert (False, 'Failed 0 size exception test.')
119 except Exception, e:
120 print e
121 print 'Passed 0 size exception Test'
122
123 myData5=escript.Data(a,myFuncSpac,True)
124 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