1 module Tests.Tetrahedron
4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
7 import Test.QuickCheck (Property, (==>))
12 import Tests.FunctionValues()
14 import ThreeDimensional
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
24 assertEqual "volume is correct" True (vol ~= (-1/3))
30 t = Tetrahedron { v0 = p0,
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]
52 t = Tetrahedron { v0 = p0,
59 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
63 contains_point1 :: Assertion
64 contains_point1 = assertEqual "contains an inner point" True contained
66 inner_point = (1, 0, 0.5)
67 contained = contains_point t inner_point
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
80 exterior_point = (5, 2, -9.0212)
81 t = Tetrahedron { v0 = p0,
86 contained = contains_point t exterior_point
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
99 exterior_point = (0, 0, 0)
100 t = Tetrahedron { v0 = p0,
105 contained = contains_point t exterior_point
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
118 exterior_point = (0, 0, 0)
119 t = Tetrahedron { v0 = p0,
124 contained = contains_point t exterior_point
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
137 exterior_point = (0, 0, 0)
138 t = Tetrahedron { v0 = p0,
143 contained = contains_point t exterior_point
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
156 exterior_point = (0, 0, 0)
157 t = Tetrahedron { v0 = p0,
162 contained = contains_point t exterior_point
165 -- | The barycentric coordinate of v0 with respect to itself should
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
171 -- | The barycentric coordinate of v1 with respect to v0 should
173 prop_b0_v1_always_zero :: Tetrahedron -> Property
174 prop_b0_v1_always_zero t =
175 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
177 -- | The barycentric coordinate of v2 with respect to v0 should
179 prop_b0_v2_always_zero :: Tetrahedron -> Property
180 prop_b0_v2_always_zero t =
181 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
183 -- | The barycentric coordinate of v3 with respect to v0 should
185 prop_b0_v3_always_zero :: Tetrahedron -> Property
186 prop_b0_v3_always_zero t =
187 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
189 -- | The barycentric coordinate of v1 with respect to itself should
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
195 -- | The barycentric coordinate of v0 with respect to v1 should
197 prop_b1_v0_always_zero :: Tetrahedron -> Property
198 prop_b1_v0_always_zero t =
199 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
201 -- | The barycentric coordinate of v2 with respect to v1 should
203 prop_b1_v2_always_zero :: Tetrahedron -> Property
204 prop_b1_v2_always_zero t =
205 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
207 -- | The barycentric coordinate of v3 with respect to v1 should
209 prop_b1_v3_always_zero :: Tetrahedron -> Property
210 prop_b1_v3_always_zero t =
211 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
213 -- | The barycentric coordinate of v2 with respect to itself should
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
219 -- | The barycentric coordinate of v0 with respect to v2 should
221 prop_b2_v0_always_zero :: Tetrahedron -> Property
222 prop_b2_v0_always_zero t =
223 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
225 -- | The barycentric coordinate of v1 with respect to v2 should
227 prop_b2_v1_always_zero :: Tetrahedron -> Property
228 prop_b2_v1_always_zero t =
229 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
231 -- | The barycentric coordinate of v3 with respect to v2 should
233 prop_b2_v3_always_zero :: Tetrahedron -> Property
234 prop_b2_v3_always_zero t =
235 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
237 -- | The barycentric coordinate of v3 with respect to itself should
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
243 -- | The barycentric coordinate of v0 with respect to v3 should
245 prop_b3_v0_always_zero :: Tetrahedron -> Property
246 prop_b3_v0_always_zero t =
247 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
249 -- | The barycentric coordinate of v1 with respect to v3 should
251 prop_b3_v1_always_zero :: Tetrahedron -> Property
252 prop_b3_v1_always_zero t =
253 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
255 -- | The barycentric coordinate of v2 with respect to v3 should
257 prop_b3_v2_always_zero :: Tetrahedron -> Property
258 prop_b3_v2_always_zero t =
259 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
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)
266 -- | Given in Sorokina and Zeilfelder, p. 78.
267 prop_c3000_identity :: Tetrahedron -> Property
268 prop_c3000_identity t =
270 c t 3 0 0 0 ~= p t 3 0 0 0
272 -- | Given in Sorokina and Zeilfelder, p. 78.
273 prop_c2100_identity :: Tetrahedron -> Property
274 prop_c2100_identity t =
276 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
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)
283 -- | Given in Sorokina and Zeilfelder, p. 78.
284 prop_c1110_identity :: Tetrahedron -> Property
285 prop_c1110_identity t =
287 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
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))
294 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
295 prop_x_rotation_doesnt_affect_front t =
298 fv0 = Tetrahedron.fv t
299 fv1 = rotate cwx (Tetrahedron.fv t)
303 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
304 prop_x_rotation_doesnt_affect_back t =
307 fv0 = Tetrahedron.fv t
308 fv1 = rotate cwx (Tetrahedron.fv t)
313 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
314 prop_y_rotation_doesnt_affect_left t =
317 fv0 = Tetrahedron.fv t
318 fv1 = rotate cwy (Tetrahedron.fv t)
322 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
323 prop_y_rotation_doesnt_affect_right t =
326 fv0 = Tetrahedron.fv t
327 fv1 = rotate cwy (Tetrahedron.fv t)
332 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
333 prop_z_rotation_doesnt_affect_down t =
336 fv0 = Tetrahedron.fv t
337 fv1 = rotate cwz (Tetrahedron.fv t)
342 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
343 prop_z_rotation_doesnt_affect_top t =
346 fv0 = Tetrahedron.fv t
347 fv1 = rotate cwz (Tetrahedron.fv t)
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
355 t' = t { v0 = (v1 t), v1 = (v0 t) }
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
361 t' = t { v2 = (v3 t), v3 = (v2 t) }
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
367 t' = t { v2 = (v3 t), v3 = (v2 t) }
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
373 t' = t { v0 = (v3 t), v3 = (v0 t) }