]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Tetrahedron.hs
a2a7b6ebdf54fdaf6e8cdf729e4fe49d05d41ee1
[spline3.git] / src / Tests / Tetrahedron.hs
1 module Tests.Tetrahedron
2 where
3
4 import Test.HUnit
5 import Test.QuickCheck (Property, (==>))
6
7 import Cardinal
8 import Comparisons
9 import FunctionValues
10 import Tests.FunctionValues()
11 import Tetrahedron
12 import ThreeDimensional
13
14 -- HUnit Tests
15
16
17 -- | Check the volume of a particular tetrahedron against the value
18 -- computed by hand. Its vertices are in clockwise order, so the
19 -- volume should be negative.
20 test_volume1 :: Assertion
21 test_volume1 =
22 assertEqual "volume is correct" True (vol ~= (-1/3))
23 where
24 p0 = (0, -0.5, 0)
25 p1 = (0, 0.5, 0)
26 p2 = (2, 0, 0)
27 p3 = (1, 0, 1)
28 t = Tetrahedron { v0 = p0,
29 v1 = p1,
30 v2 = p2,
31 v3 = p3,
32 fv = empty_values }
33 vol = volume t
34
35
36 -- | Check the volume of a particular tetrahedron against the value
37 -- computed by hand. Its vertices are in counter-clockwise order, so
38 -- the volume should be positive.
39 test_volume2 :: Assertion
40 test_volume2 =
41 assertEqual "volume is correct" True (vol ~= (1/3))
42 where
43 p0 = (0, -0.5, 0)
44 p1 = (2, 0, 0)
45 p2 = (0, 0.5, 0)
46 p3 = (1, 0, 1)
47 t = Tetrahedron { v0 = p0,
48 v1 = p1,
49 v2 = p2,
50 v3 = p3,
51 fv = empty_values }
52 vol = volume t
53
54
55 -- | Ensure that a tetrahedron contains a particular point chosen to
56 -- be inside of it.
57 test_contains_point1 :: Assertion
58 test_contains_point1 =
59 assertEqual "contains an inner point" True (contains_point t inner_point)
60 where
61 p0 = (0, -0.5, 0)
62 p1 = (0, 0.5, 0)
63 p2 = (2, 0, 0)
64 p3 = (1, 0, 1)
65 inner_point = (1, 0, 0.5)
66 t = Tetrahedron { v0 = p0,
67 v1 = p1,
68 v2 = p2,
69 v3 = p3,
70 fv = empty_values }
71
72
73 -- | Ensure that a tetrahedron does not contain a particular point chosen to
74 -- be outside of it (first test).
75 test_doesnt_contain_point1 :: Assertion
76 test_doesnt_contain_point1 =
77 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
78 where
79 p0 = (0, -0.5, 0)
80 p1 = (0, 0.5, 0)
81 p2 = (2, 0, 0)
82 p3 = (1, 0, 1)
83 exterior_point = (5, 2, -9.0212)
84 t = Tetrahedron { v0 = p0,
85 v1 = p1,
86 v2 = p2,
87 v3 = p3,
88 fv = empty_values }
89
90
91 -- | Ensure that a tetrahedron does not contain a particular point chosen to
92 -- be outside of it (second test).
93 test_doesnt_contain_point2 :: Assertion
94 test_doesnt_contain_point2 =
95 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
96 where
97 p0 = (0, 1, 1)
98 p1 = (1, 1, 1)
99 p2 = (0.5, 0.5, 1)
100 p3 = (0.5, 0.5, 0.5)
101 exterior_point = (0, 0, 0)
102 t = Tetrahedron { v0 = p0,
103 v1 = p1,
104 v2 = p2,
105 v3 = p3,
106 fv = empty_values }
107
108
109 -- | Ensure that a tetrahedron does not contain a particular point chosen to
110 -- be outside of it (third test).
111 test_doesnt_contain_point3 :: Assertion
112 test_doesnt_contain_point3 =
113 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
114 where
115 p0 = (1, 1, 1)
116 p1 = (1, 0, 1)
117 p2 = (0.5, 0.5, 1)
118 p3 = (0.5, 0.5, 0.5)
119 exterior_point = (0, 0, 0)
120 t = Tetrahedron { v0 = p0,
121 v1 = p1,
122 v2 = p2,
123 v3 = p3,
124 fv = empty_values }
125
126
127 -- | Ensure that a tetrahedron does not contain a particular point chosen to
128 -- be outside of it (fourth test).
129 test_doesnt_contain_point4 :: Assertion
130 test_doesnt_contain_point4 =
131 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
132 where
133 p0 = (1, 0, 1)
134 p1 = (0, 0, 1)
135 p2 = (0.5, 0.5, 1)
136 p3 = (0.5, 0.5, 0.5)
137 exterior_point = (0, 0, 0)
138 t = Tetrahedron { v0 = p0,
139 v1 = p1,
140 v2 = p2,
141 v3 = p3,
142 fv = empty_values }
143
144
145 -- | Ensure that a tetrahedron does not contain a particular point chosen to
146 -- be outside of it (fifth test).
147 test_doesnt_contain_point5 :: Assertion
148 test_doesnt_contain_point5 =
149 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
150 where
151 p0 = (0, 0, 1)
152 p1 = (0, 1, 1)
153 p2 = (0.5, 0.5, 1)
154 p3 = (0.5, 0.5, 0.5)
155 exterior_point = (0, 0, 0)
156 t = Tetrahedron { v0 = p0,
157 v1 = p1,
158 v2 = p2,
159 v3 = p3,
160 fv = empty_values }
161
162
163 -- | The barycentric coordinate of v0 with respect to itself should
164 -- be one.
165 prop_b0_v0_always_unity :: Tetrahedron -> Property
166 prop_b0_v0_always_unity t =
167 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
168
169 -- | The barycentric coordinate of v1 with respect to v0 should
170 -- be zero.
171 prop_b0_v1_always_zero :: Tetrahedron -> Property
172 prop_b0_v1_always_zero t =
173 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
174
175 -- | The barycentric coordinate of v2 with respect to v0 should
176 -- be zero.
177 prop_b0_v2_always_zero :: Tetrahedron -> Property
178 prop_b0_v2_always_zero t =
179 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
180
181 -- | The barycentric coordinate of v3 with respect to v0 should
182 -- be zero.
183 prop_b0_v3_always_zero :: Tetrahedron -> Property
184 prop_b0_v3_always_zero t =
185 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
186
187 -- | The barycentric coordinate of v1 with respect to itself should
188 -- be one.
189 prop_b1_v1_always_unity :: Tetrahedron -> Property
190 prop_b1_v1_always_unity t =
191 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
192
193 -- | The barycentric coordinate of v0 with respect to v1 should
194 -- be zero.
195 prop_b1_v0_always_zero :: Tetrahedron -> Property
196 prop_b1_v0_always_zero t =
197 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
198
199 -- | The barycentric coordinate of v2 with respect to v1 should
200 -- be zero.
201 prop_b1_v2_always_zero :: Tetrahedron -> Property
202 prop_b1_v2_always_zero t =
203 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
204
205 -- | The barycentric coordinate of v3 with respect to v1 should
206 -- be zero.
207 prop_b1_v3_always_zero :: Tetrahedron -> Property
208 prop_b1_v3_always_zero t =
209 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
210
211 -- | The barycentric coordinate of v2 with respect to itself should
212 -- be one.
213 prop_b2_v2_always_unity :: Tetrahedron -> Property
214 prop_b2_v2_always_unity t =
215 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
216
217 -- | The barycentric coordinate of v0 with respect to v2 should
218 -- be zero.
219 prop_b2_v0_always_zero :: Tetrahedron -> Property
220 prop_b2_v0_always_zero t =
221 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
222
223 -- | The barycentric coordinate of v1 with respect to v2 should
224 -- be zero.
225 prop_b2_v1_always_zero :: Tetrahedron -> Property
226 prop_b2_v1_always_zero t =
227 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
228
229 -- | The barycentric coordinate of v3 with respect to v2 should
230 -- be zero.
231 prop_b2_v3_always_zero :: Tetrahedron -> Property
232 prop_b2_v3_always_zero t =
233 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
234
235 -- | The barycentric coordinate of v3 with respect to itself should
236 -- be one.
237 prop_b3_v3_always_unity :: Tetrahedron -> Property
238 prop_b3_v3_always_unity t =
239 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
240
241 -- | The barycentric coordinate of v0 with respect to v3 should
242 -- be zero.
243 prop_b3_v0_always_zero :: Tetrahedron -> Property
244 prop_b3_v0_always_zero t =
245 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
246
247 -- | The barycentric coordinate of v1 with respect to v3 should
248 -- be zero.
249 prop_b3_v1_always_zero :: Tetrahedron -> Property
250 prop_b3_v1_always_zero t =
251 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
252
253 -- | The barycentric coordinate of v2 with respect to v3 should
254 -- be zero.
255 prop_b3_v2_always_zero :: Tetrahedron -> Property
256 prop_b3_v2_always_zero t =
257 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
258
259
260 -- | Used for convenience in the next few tests; not a test itself.
261 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
262 p t i j k l = (polynomial t) (xi t i j k l)
263
264 -- | Given in Sorokina and Zeilfelder, p. 78.
265 prop_c3000_identity :: Tetrahedron -> Property
266 prop_c3000_identity t =
267 (volume t) > 0 ==>
268 c t 3 0 0 0 ~= p t 3 0 0 0
269
270 -- | Given in Sorokina and Zeilfelder, p. 78.
271 prop_c2100_identity :: Tetrahedron -> Property
272 prop_c2100_identity t =
273 (volume t) > 0 ==>
274 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
275 where
276 term1 = (1/3)*(p t 0 3 0 0)
277 term2 = (5/6)*(p t 3 0 0 0)
278 term3 = 3*(p t 2 1 0 0)
279 term4 = (3/2)*(p t 1 2 0 0)
280
281 -- | Given in Sorokina and Zeilfelder, p. 78.
282 prop_c1110_identity :: Tetrahedron -> Property
283 prop_c1110_identity t =
284 (volume t) > 0 ==>
285 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
286 where
287 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
288 term2 = (9/2)*(p t 1 1 1 0)
289 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
290 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
291
292 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
293 prop_x_rotation_doesnt_affect_front t =
294 expr1 == expr2
295 where
296 fv0 = Tetrahedron.fv t
297 fv1 = rotate cwx (Tetrahedron.fv t)
298 expr1 = front fv0
299 expr2 = front fv1
300
301 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
302 prop_x_rotation_doesnt_affect_back t =
303 expr1 == expr2
304 where
305 fv0 = Tetrahedron.fv t
306 fv1 = rotate cwx (Tetrahedron.fv t)
307 expr1 = back fv0
308 expr2 = back fv1
309
310
311 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
312 prop_y_rotation_doesnt_affect_left t =
313 expr1 == expr2
314 where
315 fv0 = Tetrahedron.fv t
316 fv1 = rotate cwy (Tetrahedron.fv t)
317 expr1 = left fv0
318 expr2 = left fv1
319
320 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
321 prop_y_rotation_doesnt_affect_right t =
322 expr1 == expr2
323 where
324 fv0 = Tetrahedron.fv t
325 fv1 = rotate cwy (Tetrahedron.fv t)
326 expr1 = right fv0
327 expr2 = right fv1
328
329
330 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
331 prop_z_rotation_doesnt_affect_down t =
332 expr1 == expr2
333 where
334 fv0 = Tetrahedron.fv t
335 fv1 = rotate cwz (Tetrahedron.fv t)
336 expr1 = down fv0
337 expr2 = down fv1
338
339
340 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
341 prop_z_rotation_doesnt_affect_top t =
342 expr1 == expr2
343 where
344 fv0 = Tetrahedron.fv t
345 fv1 = rotate cwz (Tetrahedron.fv t)
346 expr1 = top fv0
347 expr2 = top fv1
348
349 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
350 prop_swapping_vertices_doesnt_affect_coefficients1 t =
351 c t 0 0 1 2 == c t' 0 0 1 2
352 where
353 t' = t { v0 = (v1 t), v1 = (v0 t) }
354
355 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
356 prop_swapping_vertices_doesnt_affect_coefficients2 t =
357 c t 0 1 1 1 == c t' 0 1 1 1
358 where
359 t' = t { v2 = (v3 t), v3 = (v2 t) }
360
361 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
362 prop_swapping_vertices_doesnt_affect_coefficients3 t =
363 c t 2 1 0 0 == c t' 2 1 0 0
364 where
365 t' = t { v2 = (v3 t), v3 = (v2 t) }
366
367 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
368 prop_swapping_vertices_doesnt_affect_coefficients4 t =
369 c t 2 0 0 1 == c t' 2 0 0 1
370 where
371 t' = t { v0 = (v3 t), v3 = (v0 t) }