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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.104  
changed lines
  Added in v.155

  ViewVC Help
Powered by ViewVC 1.1.26