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

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

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

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

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

  ViewVC Help
Powered by ViewVC 1.1.26