/[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 613 - (show annotations)
Wed Mar 22 01:12:32 2006 UTC (14 years, 8 months ago) by elspeth
File MIME type: text/x-python
File size: 3756 byte(s)
More copyright information inserted.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26