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