/[escript]/branches/symbolic_from_3470/escript/test/python/run_symbolic.py
ViewVC logotype

Diff of /branches/symbolic_from_3470/escript/test/python/run_symbolic.py

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

revision 3477 by caltinay, Fri Mar 18 00:20:06 2011 UTC revision 3491 by caltinay, Wed Mar 30 06:13:34 2011 UTC
# Line 65  class SymbolicTestCase(unittest.TestCase Line 65  class SymbolicTestCase(unittest.TestCase
65          self.assertEqual(e(x=3), (9,27,81,243), "wrong result after __call__")          self.assertEqual(e(x=3), (9,27,81,243), "wrong result after __call__")
66    
67          xx=RandomData((4,), FunctionSpace())          xx=RandomData((4,), FunctionSpace())
68          ref=[x.toListOfTuples() for x in (xx**2, xx**3, xx**4, xx**5)]          ref=[d.toListOfTuples() for d in (xx**2, xx**3, xx**4, xx**5)]
69          res=e(x=xx)          res=e(x=xx)
70          for d in res:          for d in res:
71              self.assertTrue(isinstance(d, Data), "substituted expression not a Data object")              self.assertTrue(isinstance(d, Data), "substituted expression not a Data object")
# Line 74  class SymbolicTestCase(unittest.TestCase Line 74  class SymbolicTestCase(unittest.TestCase
74    
75      #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++      #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76    
77        def test_Functions(self):
78            import esys.escript as es
79            x=Symbol('x')
80            xx=RandomData((4,4), FunctionSpace())
81            TOL_DIGITS=8
82    
83            y=wherePositive(x)
84            ref=es.wherePositive(xx).toListOfTuples()
85            res=Evaluator(y)(x=xx)[0].toListOfTuples()
86            self.assertEqual(res, ref, "wrong result for wherePositive()")
87    
88            y=whereNonPositive(x)
89            ref=es.whereNonPositive(xx).toListOfTuples()
90            res=Evaluator(y)(x=xx)[0].toListOfTuples()
91            self.assertEqual(res, ref, "wrong result for whereNonPositive()")
92    
93            y=whereNegative(x)
94            ref=es.whereNegative(xx).toListOfTuples()
95            res=Evaluator(y)(x=xx)[0].toListOfTuples()
96            self.assertEqual(res, ref, "wrong result for whereNegative()")
97    
98            y=whereNonNegative(x)
99            ref=es.whereNonNegative(xx).toListOfTuples()
100            res=Evaluator(y)(x=xx)[0].toListOfTuples()
101            self.assertEqual(res, ref, "wrong result for whereNonNegative()")
102    
103            y=whereZero(x)
104            ref=es.whereZero(xx).toListOfTuples()
105            res=Evaluator(y)(x=xx)[0].toListOfTuples()
106            self.assertEqual(res, ref, "wrong result for whereZero()")
107    
108            y=whereNonZero(x)
109            ref=es.whereNonZero(xx).toListOfTuples()
110            res=Evaluator(y)(x=xx)[0].toListOfTuples()
111            self.assertEqual(res, ref, "wrong result for whereNonZero()")
112    
113            y=log10(x)
114            ref=es.log10(xx)
115            res=Evaluator(y)(x=xx)[0]
116            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for log10()")
117    
118            y=inverse(x)
119            ref=es.inverse(xx)
120            res=Evaluator(y)(x=xx)[0]
121            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for inverse()")
122    
123            y=minval(x)
124            ref=es.minval(xx)
125            res=Evaluator(y)(x=xx)[0]
126            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for minval()")
127    
128            y=maxval(x)
129            ref=es.maxval(xx)
130            res=Evaluator(y)(x=xx)[0]
131            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for maxval()")
132    
133            y=trace(x)
134            ref=es.trace(xx)
135            res=Evaluator(y)(x=xx)[0]
136            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for trace()")
137    
138            y=transpose(x)
139            ref=es.transpose(xx)
140            res=Evaluator(y)(x=xx)[0]
141            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for transpose()")
142    
143            y=symmetric(x)
144            ref=es.symmetric(xx)
145            res=Evaluator(y)(x=xx)[0]
146            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for symmetric()")
147    
148            y=nonsymmetric(x)
149            ref=es.nonsymmetric(xx)
150            res=Evaluator(y)(x=xx)[0]
151            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for nonsymmetric()")
152    
153            y=swap_axes(x)
154            ref=es.swap_axes(xx)
155            res=Evaluator(y)(x=xx)[0]
156            self.assertAlmostEqual(es.Lsup(res-ref), 0.0, TOL_DIGITS, "wrong result for swap_axes()")
157    
158            #y=grad(x)
159            #ref=es.grad(xx).toListOfTuples()
160            #res=Evaluator(y)(x=xx)[0].toListOfTuples()
161            #self.assertEqual(res, ref, "wrong result for grad()")
162    
163    
164  if __name__ == "__main__":  if __name__ == "__main__":
165      suite = unittest.TestSuite()      suite = unittest.TestSuite()
166      suite.addTest(unittest.makeSuite(SymbolicTestCase))      suite.addTest(unittest.makeSuite(SymbolicTestCase))

Legend:
Removed from v.3477  
changed lines
  Added in v.3491

  ViewVC Help
Powered by ViewVC 1.1.26