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 (computed by hand)
20 -- and whether or not it contains a specific point chosen to be
21 -- outside of it. Its vertices are in clockwise order, so the volume
22 -- should be negative.
23 tetrahedron1_geometry_tests :: Test.Framework.Test
24 tetrahedron1_geometry_tests =
25 testGroup "tetrahedron1 geometry"
26 [ testCase "volume1" volume1,
27 testCase "doesn't contain point1" doesnt_contain_point1]
33 t = Tetrahedron { v0 = p0,
38 precomputed_volume = 0 }
42 assertEqual "volume is correct" True (vol ~= (-1/3))
46 doesnt_contain_point1 :: Assertion
47 doesnt_contain_point1 =
48 assertEqual "doesn't contain an exterior point" False contained
50 exterior_point = (5, 2, -9.0212)
51 contained = contains_point t exterior_point
54 -- | Check the volume of a particular tetrahedron (computed by hand)
55 -- and whether or not it contains a specific point chosen to be
56 -- inside of it. Its vertices are in counter-clockwise order, so the
57 -- volume should be positive.
58 tetrahedron2_geometry_tests :: Test.Framework.Test
59 tetrahedron2_geometry_tests =
60 testGroup "tetrahedron2 geometry"
61 [ testCase "volume1" volume1,
62 testCase "contains point1" contains_point1]
68 t = Tetrahedron { v0 = p0,
73 precomputed_volume = 0 }
76 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
80 contains_point1 :: Assertion
81 contains_point1 = assertEqual "contains an inner point" True contained
83 inner_point = (1, 0, 0.5)
84 contained = contains_point t inner_point
87 -- | Ensure that tetrahedra do not contain a particular point chosen to
88 -- be outside of them.
89 containment_tests :: Test.Framework.Test
91 testGroup "containment tests"
92 [ testCase "doesn't contain point2" doesnt_contain_point2,
93 testCase "doesn't contain point3" doesnt_contain_point3,
94 testCase "doesn't contain point4" doesnt_contain_point4,
95 testCase "doesn't contain point5" doesnt_contain_point5]
99 exterior_point = (0, 0, 0)
101 doesnt_contain_point2 :: Assertion
102 doesnt_contain_point2 =
103 assertEqual "doesn't contain an exterior point" False contained
107 t = Tetrahedron { v0 = p0,
112 precomputed_volume = 0 }
113 contained = contains_point t exterior_point
116 doesnt_contain_point3 :: Assertion
117 doesnt_contain_point3 =
118 assertEqual "doesn't contain an exterior point" False contained
122 t = Tetrahedron { v0 = p0,
127 precomputed_volume = 0 }
128 contained = contains_point t exterior_point
131 doesnt_contain_point4 :: Assertion
132 doesnt_contain_point4 =
133 assertEqual "doesn't contain an exterior point" False contained
137 t = Tetrahedron { v0 = p0,
142 precomputed_volume = 0 }
143 contained = contains_point t exterior_point
146 doesnt_contain_point5 :: Assertion
147 doesnt_contain_point5 =
148 assertEqual "doesn't contain an exterior point" False contained
152 t = Tetrahedron { v0 = p0,
157 precomputed_volume = 0 }
158 contained = contains_point t exterior_point
161 -- | The barycentric coordinate of v0 with respect to itself should
163 prop_b0_v0_always_unity :: Tetrahedron -> Property
164 prop_b0_v0_always_unity t =
165 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
167 -- | The barycentric coordinate of v1 with respect to v0 should
169 prop_b0_v1_always_zero :: Tetrahedron -> Property
170 prop_b0_v1_always_zero t =
171 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
173 -- | The barycentric coordinate of v2 with respect to v0 should
175 prop_b0_v2_always_zero :: Tetrahedron -> Property
176 prop_b0_v2_always_zero t =
177 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
179 -- | The barycentric coordinate of v3 with respect to v0 should
181 prop_b0_v3_always_zero :: Tetrahedron -> Property
182 prop_b0_v3_always_zero t =
183 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
185 -- | The barycentric coordinate of v1 with respect to itself should
187 prop_b1_v1_always_unity :: Tetrahedron -> Property
188 prop_b1_v1_always_unity t =
189 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
191 -- | The barycentric coordinate of v0 with respect to v1 should
193 prop_b1_v0_always_zero :: Tetrahedron -> Property
194 prop_b1_v0_always_zero t =
195 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
197 -- | The barycentric coordinate of v2 with respect to v1 should
199 prop_b1_v2_always_zero :: Tetrahedron -> Property
200 prop_b1_v2_always_zero t =
201 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
203 -- | The barycentric coordinate of v3 with respect to v1 should
205 prop_b1_v3_always_zero :: Tetrahedron -> Property
206 prop_b1_v3_always_zero t =
207 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
209 -- | The barycentric coordinate of v2 with respect to itself should
211 prop_b2_v2_always_unity :: Tetrahedron -> Property
212 prop_b2_v2_always_unity t =
213 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
215 -- | The barycentric coordinate of v0 with respect to v2 should
217 prop_b2_v0_always_zero :: Tetrahedron -> Property
218 prop_b2_v0_always_zero t =
219 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
221 -- | The barycentric coordinate of v1 with respect to v2 should
223 prop_b2_v1_always_zero :: Tetrahedron -> Property
224 prop_b2_v1_always_zero t =
225 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
227 -- | The barycentric coordinate of v3 with respect to v2 should
229 prop_b2_v3_always_zero :: Tetrahedron -> Property
230 prop_b2_v3_always_zero t =
231 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
233 -- | The barycentric coordinate of v3 with respect to itself should
235 prop_b3_v3_always_unity :: Tetrahedron -> Property
236 prop_b3_v3_always_unity t =
237 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
239 -- | The barycentric coordinate of v0 with respect to v3 should
241 prop_b3_v0_always_zero :: Tetrahedron -> Property
242 prop_b3_v0_always_zero t =
243 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
245 -- | The barycentric coordinate of v1 with respect to v3 should
247 prop_b3_v1_always_zero :: Tetrahedron -> Property
248 prop_b3_v1_always_zero t =
249 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
251 -- | The barycentric coordinate of v2 with respect to v3 should
253 prop_b3_v2_always_zero :: Tetrahedron -> Property
254 prop_b3_v2_always_zero t =
255 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
258 -- | Used for convenience in the next few tests; not a test itself.
259 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
260 p t i j k l = (polynomial t) (xi t i j k l)
262 -- | Given in Sorokina and Zeilfelder, p. 78.
263 prop_c3000_identity :: Tetrahedron -> Property
264 prop_c3000_identity t =
266 c t 3 0 0 0 ~= p t 3 0 0 0
268 -- | Given in Sorokina and Zeilfelder, p. 78.
269 prop_c2100_identity :: Tetrahedron -> Property
270 prop_c2100_identity t =
272 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
274 term1 = (1/3)*(p t 0 3 0 0)
275 term2 = (5/6)*(p t 3 0 0 0)
276 term3 = 3*(p t 2 1 0 0)
277 term4 = (3/2)*(p t 1 2 0 0)
279 -- | Given in Sorokina and Zeilfelder, p. 78.
280 prop_c1110_identity :: Tetrahedron -> Property
281 prop_c1110_identity t =
283 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
285 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
286 term2 = (9/2)*(p t 1 1 1 0)
287 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
288 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
290 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
291 prop_x_rotation_doesnt_affect_front t =
294 fv0 = Tetrahedron.fv t
295 fv1 = rotate cwx (Tetrahedron.fv t)
299 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
300 prop_x_rotation_doesnt_affect_back t =
303 fv0 = Tetrahedron.fv t
304 fv1 = rotate cwx (Tetrahedron.fv t)
309 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
310 prop_y_rotation_doesnt_affect_left t =
313 fv0 = Tetrahedron.fv t
314 fv1 = rotate cwy (Tetrahedron.fv t)
318 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
319 prop_y_rotation_doesnt_affect_right t =
322 fv0 = Tetrahedron.fv t
323 fv1 = rotate cwy (Tetrahedron.fv t)
328 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
329 prop_z_rotation_doesnt_affect_down t =
332 fv0 = Tetrahedron.fv t
333 fv1 = rotate cwz (Tetrahedron.fv t)
338 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
339 prop_z_rotation_doesnt_affect_top t =
342 fv0 = Tetrahedron.fv t
343 fv1 = rotate cwz (Tetrahedron.fv t)
347 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
348 prop_swapping_vertices_doesnt_affect_coefficients1 t =
349 c t 0 0 1 2 == c t' 0 0 1 2
351 t' = t { v0 = (v1 t), v1 = (v0 t) }
353 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
354 prop_swapping_vertices_doesnt_affect_coefficients2 t =
355 c t 0 1 1 1 == c t' 0 1 1 1
357 t' = t { v2 = (v3 t), v3 = (v2 t) }
359 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
360 prop_swapping_vertices_doesnt_affect_coefficients3 t =
361 c t 2 1 0 0 == c t' 2 1 0 0
363 t' = t { v2 = (v3 t), v3 = (v2 t) }
365 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
366 prop_swapping_vertices_doesnt_affect_coefficients4 t =
367 c t 2 0 0 1 == c t' 2 0 0 1
369 t' = t { v0 = (v3 t), v3 = (v0 t) }