1 module Tests.Tetrahedron
5 import Test.QuickCheck (Property, (==>))
10 import Tests.FunctionValues()
12 import ThreeDimensional
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
22 assertEqual "volume is correct" True (vol ~= (-1/3))
28 t = Tetrahedron { v0 = p0,
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
41 assertEqual "volume is correct" True (vol ~= (1/3))
47 t = Tetrahedron { v0 = p0,
55 -- | Ensure that a tetrahedron contains a particular point chosen to
57 test_contains_point1 :: Assertion
58 test_contains_point1 =
59 assertEqual "contains an inner point" True (contains_point t inner_point)
65 inner_point = (1, 0, 0.5)
66 t = Tetrahedron { v0 = p0,
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)
83 exterior_point = (5, 2, -9.0212)
84 t = Tetrahedron { v0 = p0,
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)
101 exterior_point = (0, 0, 0)
102 t = Tetrahedron { v0 = p0,
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)
119 exterior_point = (0, 0, 0)
120 t = Tetrahedron { v0 = p0,
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)
137 exterior_point = (0, 0, 0)
138 t = Tetrahedron { v0 = p0,
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)
155 exterior_point = (0, 0, 0)
156 t = Tetrahedron { v0 = p0,
163 -- | The barycentric coordinate of v0 with respect to itself should
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
169 -- | The barycentric coordinate of v1 with respect to v0 should
171 prop_b0_v1_always_zero :: Tetrahedron -> Property
172 prop_b0_v1_always_zero t =
173 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
175 -- | The barycentric coordinate of v2 with respect to v0 should
177 prop_b0_v2_always_zero :: Tetrahedron -> Property
178 prop_b0_v2_always_zero t =
179 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
181 -- | The barycentric coordinate of v3 with respect to v0 should
183 prop_b0_v3_always_zero :: Tetrahedron -> Property
184 prop_b0_v3_always_zero t =
185 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
187 -- | The barycentric coordinate of v1 with respect to itself should
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
193 -- | The barycentric coordinate of v0 with respect to v1 should
195 prop_b1_v0_always_zero :: Tetrahedron -> Property
196 prop_b1_v0_always_zero t =
197 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
199 -- | The barycentric coordinate of v2 with respect to v1 should
201 prop_b1_v2_always_zero :: Tetrahedron -> Property
202 prop_b1_v2_always_zero t =
203 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
205 -- | The barycentric coordinate of v3 with respect to v1 should
207 prop_b1_v3_always_zero :: Tetrahedron -> Property
208 prop_b1_v3_always_zero t =
209 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
211 -- | The barycentric coordinate of v2 with respect to itself should
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
217 -- | The barycentric coordinate of v0 with respect to v2 should
219 prop_b2_v0_always_zero :: Tetrahedron -> Property
220 prop_b2_v0_always_zero t =
221 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
223 -- | The barycentric coordinate of v1 with respect to v2 should
225 prop_b2_v1_always_zero :: Tetrahedron -> Property
226 prop_b2_v1_always_zero t =
227 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
229 -- | The barycentric coordinate of v3 with respect to v2 should
231 prop_b2_v3_always_zero :: Tetrahedron -> Property
232 prop_b2_v3_always_zero t =
233 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
235 -- | The barycentric coordinate of v3 with respect to itself should
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
241 -- | The barycentric coordinate of v0 with respect to v3 should
243 prop_b3_v0_always_zero :: Tetrahedron -> Property
244 prop_b3_v0_always_zero t =
245 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
247 -- | The barycentric coordinate of v1 with respect to v3 should
249 prop_b3_v1_always_zero :: Tetrahedron -> Property
250 prop_b3_v1_always_zero t =
251 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
253 -- | The barycentric coordinate of v2 with respect to v3 should
255 prop_b3_v2_always_zero :: Tetrahedron -> Property
256 prop_b3_v2_always_zero t =
257 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
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)
264 -- | Given in Sorokina and Zeilfelder, p. 78.
265 prop_c3000_identity :: Tetrahedron -> Property
266 prop_c3000_identity t =
268 c t 3 0 0 0 ~= p t 3 0 0 0
270 -- | Given in Sorokina and Zeilfelder, p. 78.
271 prop_c2100_identity :: Tetrahedron -> Property
272 prop_c2100_identity t =
274 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
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)
281 -- | Given in Sorokina and Zeilfelder, p. 78.
282 prop_c1110_identity :: Tetrahedron -> Property
283 prop_c1110_identity t =
285 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
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))
292 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
293 prop_x_rotation_doesnt_affect_front t =
296 fv0 = Tetrahedron.fv t
297 fv1 = rotate cwx (Tetrahedron.fv t)
301 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
302 prop_x_rotation_doesnt_affect_back t =
305 fv0 = Tetrahedron.fv t
306 fv1 = rotate cwx (Tetrahedron.fv t)
311 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
312 prop_y_rotation_doesnt_affect_left t =
315 fv0 = Tetrahedron.fv t
316 fv1 = rotate cwy (Tetrahedron.fv t)
320 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
321 prop_y_rotation_doesnt_affect_right t =
324 fv0 = Tetrahedron.fv t
325 fv1 = rotate cwy (Tetrahedron.fv t)
330 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
331 prop_z_rotation_doesnt_affect_down t =
334 fv0 = Tetrahedron.fv t
335 fv1 = rotate cwz (Tetrahedron.fv t)
340 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
341 prop_z_rotation_doesnt_affect_top t =
344 fv0 = Tetrahedron.fv t
345 fv1 = rotate cwz (Tetrahedron.fv t)
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
353 t' = t { v0 = (v1 t), v1 = (v0 t) }
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
359 t' = t { v2 = (v3 t), v3 = (v2 t) }
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
365 t' = t { v2 = (v3 t), v3 = (v2 t) }
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
371 t' = t { v0 = (v3 t), v3 = (v0 t) }