1 module Tests.Tetrahedron
11 import Tests.FunctionValues()
13 import ThreeDimensional
15 instance Arbitrary Tetrahedron where
17 rnd_v0 <- arbitrary :: Gen Point
18 rnd_v1 <- arbitrary :: Gen Point
19 rnd_v2 <- arbitrary :: Gen Point
20 rnd_v3 <- arbitrary :: Gen Point
21 rnd_fv <- arbitrary :: Gen FunctionValues
22 return (Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3)
27 -- | Check the volume of a particular tetrahedron against the value
28 -- computed by hand. Its vertices are in clockwise order, so the
29 -- volume should be negative.
30 test_volume1 :: Assertion
32 assertEqual "volume is correct" True (vol ~= (-1/3))
38 t = Tetrahedron { v0 = p0,
46 -- | Check the volume of a particular tetrahedron against the value
47 -- computed by hand. Its vertices are in counter-clockwise order, so
48 -- the volume should be positive.
49 test_volume2 :: Assertion
51 assertEqual "volume is correct" True (vol ~= (1/3))
57 t = Tetrahedron { v0 = p0,
65 -- | Ensure that a tetrahedron contains a particular point chosen to
67 test_contains_point1 :: Assertion
68 test_contains_point1 =
69 assertEqual "contains an inner point" True (contains_point t inner_point)
75 inner_point = (1, 0, 0.5)
76 t = Tetrahedron { v0 = p0,
83 -- | Ensure that a tetrahedron does not contain a particular point chosen to
84 -- be outside of it (first test).
85 test_doesnt_contain_point1 :: Assertion
86 test_doesnt_contain_point1 =
87 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
93 exterior_point = (5, 2, -9.0212)
94 t = Tetrahedron { v0 = p0,
101 -- | Ensure that a tetrahedron does not contain a particular point chosen to
102 -- be outside of it (second test).
103 test_doesnt_contain_point2 :: Assertion
104 test_doesnt_contain_point2 =
105 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
111 exterior_point = (0, 0, 0)
112 t = Tetrahedron { v0 = p0,
119 -- | Ensure that a tetrahedron does not contain a particular point chosen to
120 -- be outside of it (third test).
121 test_doesnt_contain_point3 :: Assertion
122 test_doesnt_contain_point3 =
123 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
129 exterior_point = (0, 0, 0)
130 t = Tetrahedron { v0 = p0,
137 -- | Ensure that a tetrahedron does not contain a particular point chosen to
138 -- be outside of it (fourth test).
139 test_doesnt_contain_point4 :: Assertion
140 test_doesnt_contain_point4 =
141 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
147 exterior_point = (0, 0, 0)
148 t = Tetrahedron { v0 = p0,
155 -- | Ensure that a tetrahedron does not contain a particular point chosen to
156 -- be outside of it (fifth test).
157 test_doesnt_contain_point5 :: Assertion
158 test_doesnt_contain_point5 =
159 assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
165 exterior_point = (0, 0, 0)
166 t = Tetrahedron { v0 = p0,
173 -- | The barycentric coordinate of v0 with respect to itself should
175 prop_b0_v0_always_unity :: Tetrahedron -> Property
176 prop_b0_v0_always_unity t =
177 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
179 -- | The barycentric coordinate of v1 with respect to v0 should
181 prop_b0_v1_always_zero :: Tetrahedron -> Property
182 prop_b0_v1_always_zero t =
183 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
185 -- | The barycentric coordinate of v2 with respect to v0 should
187 prop_b0_v2_always_zero :: Tetrahedron -> Property
188 prop_b0_v2_always_zero t =
189 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
191 -- | The barycentric coordinate of v3 with respect to v0 should
193 prop_b0_v3_always_zero :: Tetrahedron -> Property
194 prop_b0_v3_always_zero t =
195 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
197 -- | The barycentric coordinate of v1 with respect to itself should
199 prop_b1_v1_always_unity :: Tetrahedron -> Property
200 prop_b1_v1_always_unity t =
201 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
203 -- | The barycentric coordinate of v0 with respect to v1 should
205 prop_b1_v0_always_zero :: Tetrahedron -> Property
206 prop_b1_v0_always_zero t =
207 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
209 -- | The barycentric coordinate of v2 with respect to v1 should
211 prop_b1_v2_always_zero :: Tetrahedron -> Property
212 prop_b1_v2_always_zero t =
213 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
215 -- | The barycentric coordinate of v3 with respect to v1 should
217 prop_b1_v3_always_zero :: Tetrahedron -> Property
218 prop_b1_v3_always_zero t =
219 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
221 -- | The barycentric coordinate of v2 with respect to itself should
223 prop_b2_v2_always_unity :: Tetrahedron -> Property
224 prop_b2_v2_always_unity t =
225 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
227 -- | The barycentric coordinate of v0 with respect to v2 should
229 prop_b2_v0_always_zero :: Tetrahedron -> Property
230 prop_b2_v0_always_zero t =
231 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
233 -- | The barycentric coordinate of v1 with respect to v2 should
235 prop_b2_v1_always_zero :: Tetrahedron -> Property
236 prop_b2_v1_always_zero t =
237 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
239 -- | The barycentric coordinate of v3 with respect to v2 should
241 prop_b2_v3_always_zero :: Tetrahedron -> Property
242 prop_b2_v3_always_zero t =
243 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
245 -- | The barycentric coordinate of v3 with respect to itself should
247 prop_b3_v3_always_unity :: Tetrahedron -> Property
248 prop_b3_v3_always_unity t =
249 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
251 -- | The barycentric coordinate of v0 with respect to v3 should
253 prop_b3_v0_always_zero :: Tetrahedron -> Property
254 prop_b3_v0_always_zero t =
255 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
257 -- | The barycentric coordinate of v1 with respect to v3 should
259 prop_b3_v1_always_zero :: Tetrahedron -> Property
260 prop_b3_v1_always_zero t =
261 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
263 -- | The barycentric coordinate of v2 with respect to v3 should
265 prop_b3_v2_always_zero :: Tetrahedron -> Property
266 prop_b3_v2_always_zero t =
267 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
270 -- | Used for convenience in the next few tests; not a test itself.
271 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
272 p t i j k l = (polynomial t) (xi t i j k l)
274 -- | Given in Sorokina and Zeilfelder, p. 78.
275 prop_c3000_identity :: Tetrahedron -> Property
276 prop_c3000_identity t =
278 c t 3 0 0 0 ~= p t 3 0 0 0
280 -- | Given in Sorokina and Zeilfelder, p. 78.
281 prop_c2100_identity :: Tetrahedron -> Property
282 prop_c2100_identity t =
284 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
286 term1 = (1/3)*(p t 0 3 0 0)
287 term2 = (5/6)*(p t 3 0 0 0)
288 term3 = 3*(p t 2 1 0 0)
289 term4 = (3/2)*(p t 1 2 0 0)
291 -- | Given in Sorokina and Zeilfelder, p. 78.
292 prop_c1110_identity :: Tetrahedron -> Property
293 prop_c1110_identity t =
295 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
297 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
298 term2 = (9/2)*(p t 1 1 1 0)
299 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
300 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
302 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
303 prop_x_rotation_doesnt_affect_front t =
306 fv0 = Tetrahedron.fv t
307 fv1 = rotate (Tetrahedron.fv t) cwx
311 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
312 prop_x_rotation_doesnt_affect_back t =
315 fv0 = Tetrahedron.fv t
316 fv1 = rotate (Tetrahedron.fv t) cwx
321 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
322 prop_y_rotation_doesnt_affect_left t =
325 fv0 = Tetrahedron.fv t
326 fv1 = rotate (Tetrahedron.fv t) cwy
330 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
331 prop_y_rotation_doesnt_affect_right t =
334 fv0 = Tetrahedron.fv t
335 fv1 = rotate (Tetrahedron.fv t) cwy
340 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
341 prop_z_rotation_doesnt_affect_down t =
344 fv0 = Tetrahedron.fv t
345 fv1 = rotate (Tetrahedron.fv t) cwz
350 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
351 prop_z_rotation_doesnt_affect_top t =
354 fv0 = Tetrahedron.fv t
355 fv1 = rotate (Tetrahedron.fv t) cwz
359 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
360 prop_swapping_vertices_doesnt_affect_coefficients1 t =
361 c t 0 0 1 2 == c t' 0 0 1 2
363 t' = t { v0 = (v1 t), v1 = (v0 t) }
365 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
366 prop_swapping_vertices_doesnt_affect_coefficients2 t =
367 c t 0 1 1 1 == c t' 0 1 1 1
369 t' = t { v2 = (v3 t), v3 = (v2 t) }
371 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
372 prop_swapping_vertices_doesnt_affect_coefficients3 t =
373 c t 2 1 0 0 == c t' 2 1 0 0
375 t' = t { v2 = (v3 t), v3 = (v2 t) }
377 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
378 prop_swapping_vertices_doesnt_affect_coefficients4 t =
379 c t 2 0 0 1 == c t' 2 0 0 1
381 t' = t { v0 = (v3 t), v3 = (v0 t) }