/[escript]/trunk/pycad/test/python/run_pycad_test.py
ViewVC logotype

Contents of /trunk/pycad/test/python/run_pycad_test.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 905 - (show annotations)
Mon Nov 20 11:23:24 2006 UTC (12 years, 9 months ago) by gross
File MIME type: text/x-python
File size: 12784 byte(s)
some tests for pycad added
1 # $Id: run_visualization_interface.py 798 2006-08-04 01:05:36Z gross $
2
3 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
4 http://www.access.edu.au
5 Primary Business: Queensland, Australia"""
6 __license__="""Licensed under the Open Software License version 3.0
7 http://www.opensource.org/licenses/osl-3.0.php"""
8 import sys
9 import unittest
10 import numarray
11 from esys.pycad import *
12
13 try:
14 PYCAD_TEST_DATA=os.environ['PYCAD_TEST_DATA']
15 except KeyError:
16 PYCAD_TEST_DATA='.'
17
18 try:
19 PYCAD_WORKDIR=os.environ['PYCAD_WORKDIR']
20 except KeyError:
21 PYCAD_WORKDIR='.'
22
23 PYCAD_TEST_MESH_PATH=PYCAD_TEST_DATA+"/data_meshes/"
24 PYCAD_WORKDIR_PATH=PYCAD_WORKDIR+"/"
25
26 class Test_PyCAD(unittest.TestCase):
27 ABS_TOL=1.e-8
28 def __distance(self,x,y):
29 return math.sqrt(numarray.dot(x-y,x-y))
30 def test_Translation_x(self):
31 t=Translation([1,0,0])
32 s0=t([1,0,0])
33 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
34 self.failUnless(self.__distance(s0,numarray.array([2,0,0]))<self.ABS_TOL,"s0 is wrong.")
35 s1=t([0,1,0])
36 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
37 self.failUnless(self.__distance(s1,numarray.array([1,1,0]))<self.ABS_TOL,"s1 is wrong.")
38 s2=t([0,0,1])
39 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
40 self.failUnless(self.__distance(s2,numarray.array([1,0,1]))<self.ABS_TOL,"s2 is wrong.")
41 def test_Translation_y(self):
42 t=Translation([0,1,0])
43 s0=t([1,0,0])
44 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
45 self.failUnless(self.__distance(s0,numarray.array([1,1,0]))<self.ABS_TOL,"s0 is wrong.")
46 s1=t([0,1,0])
47 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
48 self.failUnless(self.__distance(s1,numarray.array([0,2,0]))<self.ABS_TOL,"s1 is wrong.")
49 s2=t([0,0,1])
50 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
51 self.failUnless(self.__distance(s2,numarray.array([0,1,1]))<self.ABS_TOL,"s2 is wrong.")
52 def test_Translation_z(self):
53 t=Translation([0,0,1])
54 s0=t([1,0,0])
55 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
56 self.failUnless(self.__distance(s0,numarray.array([1,0,1]))<self.ABS_TOL,"s0 is wrong.")
57 s1=t([0,1,0])
58 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
59 self.failUnless(self.__distance(s1,numarray.array([0,1,1]))<self.ABS_TOL,"s1 is wrong.")
60 s2=t([0,0,1])
61 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
62 self.failUnless(self.__distance(s2,numarray.array([0,0,2]))<self.ABS_TOL,"s2 is wrong.")
63 def test_Dilation_0_two(self):
64 t=Dilation(2.)
65 s0=t([1,0,0])
66 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
67 self.failUnless(self.__distance(s0,numarray.array([2,0,0]))<self.ABS_TOL,"s0 is wrong.")
68 s1=t([0,1,0])
69 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
70 self.failUnless(self.__distance(s1,numarray.array([0,2,0]))<self.ABS_TOL,"s1 is wrong.")
71 s2=t([0,0,1])
72 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
73 self.failUnless(self.__distance(s2,numarray.array([0,0,2]))<self.ABS_TOL,"s2 is wrong.")
74 def test_Dilation_0_half(self):
75 t=Dilation(0.5)
76 s0=t([1,0,0])
77 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
78 self.failUnless(self.__distance(s0,numarray.array([0.5,0,0]))<self.ABS_TOL,"s0 is wrong.")
79 s1=t([0,1,0])
80 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
81 self.failUnless(self.__distance(s1,numarray.array([0,0.5,0]))<self.ABS_TOL,"s1 is wrong.")
82 s2=t([0,0,1])
83 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
84 self.failUnless(self.__distance(s2,numarray.array([0,0,0.5]))<self.ABS_TOL,"s2 is wrong.")
85 def test_Dilation_x_two(self):
86 t=Dilation(2.,[1.,0.,0.])
87 s0=t([1,0,0])
88 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
89 self.failUnless(self.__distance(s0,numarray.array([1,0,0]))<self.ABS_TOL,"s0 is wrong.")
90 s0_1=t([0,0,0])
91 self.failUnless(isinstance(s0_1,numarray.NumArray),"s0_1 is not a numarray object.")
92 self.failUnless(self.__distance(s0_1,numarray.array([-1.,0,0]))<self.ABS_TOL,"s0_1 is wrong.")
93 s1=t([0,1,0])
94 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
95 self.failUnless(self.__distance(s1,numarray.array([-1,2,0]))<self.ABS_TOL,"s1 is wrong.")
96 s2=t([0,0,1])
97 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
98 self.failUnless(self.__distance(s2,numarray.array([-1.,0,2]))<self.ABS_TOL,"s2 is wrong.")
99 def test_Dilation_x_half(self):
100 t=Dilation(0.5,[1.,0.,0.])
101 s0=t([1,0,0])
102 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
103 self.failUnless(self.__distance(s0,numarray.array([1.,0,0]))<self.ABS_TOL,"s0 is wrong.")
104 s0_1=t([0,0,0])
105 self.failUnless(isinstance(s0_1,numarray.NumArray),"s0_1 is not a numarray object.")
106 self.failUnless(self.__distance(s0_1,numarray.array([.5,0,0]))<self.ABS_TOL,"s0_1 is wrong.")
107 s1=t([0,1,0])
108 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
109 self.failUnless(self.__distance(s1,numarray.array([0.5,0.5,0]))<self.ABS_TOL,"s1 is wrong.")
110 s2=t([0,0,1])
111 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
112 self.failUnless(self.__distance(s2,numarray.array([0.5,0,0.5]))<self.ABS_TOL,"s2 is wrong.")
113 def test_Dilation_y_two(self):
114 t=Dilation(2.,[0.,1.,0.])
115 s0=t([1,0,0])
116 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
117 self.failUnless(self.__distance(s0,numarray.array([2.,-1.,0]))<self.ABS_TOL,"s0 is wrong.")
118 s1_1=t([0,0,0])
119 self.failUnless(isinstance(s1_1,numarray.NumArray),"s1_1 is not a numarray object.")
120 self.failUnless(self.__distance(s1_1,numarray.array([0.,-1.,0]))<self.ABS_TOL,"s1_1 is wrong.")
121 s1=t([0,1,0])
122 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
123 self.failUnless(self.__distance(s1,numarray.array([0.,1.,0]))<self.ABS_TOL,"s1 is wrong.")
124 s2=t([0,0,1])
125 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
126 self.failUnless(self.__distance(s2,numarray.array([0.,-1.,2]))<self.ABS_TOL,"s2 is wrong.")
127 def test_Dilation_y_half(self):
128 t=Dilation(0.5,[0.,1.,0.])
129 s0=t([1,0,0])
130 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
131 self.failUnless(self.__distance(s0,numarray.array([0.5,0.5,0]))<self.ABS_TOL,"s0 is wrong.")
132 s1_1=t([0,0,0])
133 self.failUnless(isinstance(s1_1,numarray.NumArray),"s1_1 is not a numarray object.")
134 self.failUnless(self.__distance(s1_1,numarray.array([0,0.5,0]))<self.ABS_TOL,"s1_1 is wrong.")
135 s1=t([0,1,0])
136 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
137 self.failUnless(self.__distance(s1,numarray.array([0.,1.,0]))<self.ABS_TOL,"s1 is wrong.")
138 s2=t([0,0,1])
139 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
140 self.failUnless(self.__distance(s2,numarray.array([0.,0.5,0.5]))<self.ABS_TOL,"s2 is wrong.")
141 def test_Dilation_z_two(self):
142 t=Dilation(2.,[0.,0.,1.])
143 s0=t([1,0,0])
144 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
145 self.failUnless(self.__distance(s0,numarray.array([2.,0.,-1.]))<self.ABS_TOL,"s0 is wrong.")
146 s2_1=t([0,0,0])
147 self.failUnless(isinstance(s2_1,numarray.NumArray),"s2_1 is not a numarray object.")
148 self.failUnless(self.__distance(s2_1,numarray.array([0.,0.,-1.]))<self.ABS_TOL,"s2_1 is wrong.")
149 s1=t([0,1,0])
150 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
151 self.failUnless(self.__distance(s1,numarray.array([0.,2.,-1.]))<self.ABS_TOL,"s1 is wrong.")
152 s2=t([0,0,1])
153 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
154 self.failUnless(self.__distance(s2,numarray.array([0.,0.,1.]))<self.ABS_TOL,"s2 is wrong.")
155 def test_Dilation_z_half(self):
156 t=Dilation(0.5,[0.,0.,1.])
157 s0=t([1,0,0])
158 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
159 self.failUnless(self.__distance(s0,numarray.array([0.5,0.,0.5]))<self.ABS_TOL,"s0 is wrong.")
160 s2_1=t([0,0,0])
161 self.failUnless(isinstance(s2_1,numarray.NumArray),"s2_1 is not a numarray object.")
162 self.failUnless(self.__distance(s2_1,numarray.array([0,0,0.5]))<self.ABS_TOL,"s2_1 is wrong.")
163 s1=t([0,1,0])
164 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
165 self.failUnless(self.__distance(s1,numarray.array([0.,0.5,0.5]))<self.ABS_TOL,"s1 is wrong.")
166 s2=t([0,0,1])
167 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
168 self.failUnless(self.__distance(s2,numarray.array([0.,0.,1.]))<self.ABS_TOL,"s2 is wrong.")
169 def test_Reflection_x_offset0(self):
170 t=Reflection([1.,0.,0.])
171 s0=t([1,0,0])
172 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
173 self.failUnless(self.__distance(s0,numarray.array([-1.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
174 s1=t([0,1,0])
175 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
176 self.failUnless(self.__distance(s1,numarray.array([0,1,0]))<self.ABS_TOL,"s1 is wrong.")
177 s2=t([0,0,1])
178 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
179 self.failUnless(self.__distance(s2,numarray.array([0,0,1]))<self.ABS_TOL,"s2 is wrong.")
180 s=t([1,2,3])
181 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
182 self.failUnless(self.__distance(s,numarray.array([-1.,2,3]))<self.ABS_TOL,"s is wrong.")
183 def test_Reflection_x_offset2(self):
184 t=Reflection([-2.,0.,0.],offset=-4)
185 s0=t([1,0,0])
186 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
187 self.failUnless(self.__distance(s0,numarray.array([3.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
188 s1=t([0,1,0])
189 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
190 self.failUnless(self.__distance(s1,numarray.array([4,1,0]))<self.ABS_TOL,"s1 is wrong.")
191 s2=t([0,0,1])
192 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
193 self.failUnless(self.__distance(s2,numarray.array([4,0,1]))<self.ABS_TOL,"s2 is wrong.")
194 s=t([1,2,3])
195 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
196 self.failUnless(self.__distance(s,numarray.array([3.,2,3]))<self.ABS_TOL,"s is wrong.")
197 def test_Reflection_x_offset2_vector(self):
198 t=Reflection([1.,0.,0.],offset=[2,0,0])
199 s0=t([1,0,0])
200 self.failUnless(isinstance(s0,numarray.NumArray),"s0 is not a numarray object.")
201 self.failUnless(self.__distance(s0,numarray.array([3.,0,0.]))<self.ABS_TOL,"s0 is wrong.")
202 s1=t([0,1,0])
203 self.failUnless(isinstance(s1,numarray.NumArray),"s1 is not a numarray object.")
204 self.failUnless(self.__distance(s1,numarray.array([4,1,0]))<self.ABS_TOL,"s1 is wrong.")
205 s2=t([0,0,1])
206 self.failUnless(isinstance(s2,numarray.NumArray),"s2 is not a numarray object.")
207 self.failUnless(self.__distance(s2,numarray.array([4,0,1]))<self.ABS_TOL,"s2 is wrong.")
208 s=t([1,2,3])
209 self.failUnless(isinstance(s,numarray.NumArray),"s is not a numarray object.")
210 self.failUnless(self.__distance(s,numarray.array([3.,2,3]))<self.ABS_TOL,"s is wrong.")
211 if __name__ == '__main__':
212 suite = unittest.TestSuite()
213 suite.addTest(unittest.makeSuite(Test_PyCAD))
214 s=unittest.TextTestRunner(verbosity=2).run(suite)
215 if s.wasSuccessful():
216 sys.exit(0)
217 else:
218 sys.exit(1)

  ViewVC Help
Powered by ViewVC 1.1.26