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,
41 assertEqual "volume is correct" True (vol ~= (-1/3))
45 doesnt_contain_point1 :: Assertion
46 doesnt_contain_point1 =
47 assertEqual "doesn't contain an exterior point" False contained
49 exterior_point = (5, 2, -9.0212)
50 contained = contains_point t exterior_point
53 -- | Check the volume of a particular tetrahedron (computed by hand)
54 -- and whether or not it contains a specific point chosen to be
55 -- inside of it. Its vertices are in counter-clockwise order, so the
56 -- volume should be positive.
57 tetrahedron2_geometry_tests :: Test.Framework.Test
58 tetrahedron2_geometry_tests =
59 testGroup "tetrahedron2 geometry"
60 [ testCase "volume1" volume1,
61 testCase "contains point1" contains_point1]
67 t = Tetrahedron { v0 = p0,
74 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
78 contains_point1 :: Assertion
79 contains_point1 = assertEqual "contains an inner point" True contained
81 inner_point = (1, 0, 0.5)
82 contained = contains_point t inner_point
85 -- | Ensure that tetrahedra do not contain a particular point chosen to
86 -- be outside of them.
87 containment_tests :: Test.Framework.Test
89 testGroup "containment tests"
90 [ testCase "doesn't contain point2" doesnt_contain_point2,
91 testCase "doesn't contain point3" doesnt_contain_point3,
92 testCase "doesn't contain point4" doesnt_contain_point4,
93 testCase "doesn't contain point5" doesnt_contain_point5]
97 exterior_point = (0, 0, 0)
99 doesnt_contain_point2 :: Assertion
100 doesnt_contain_point2 =
101 assertEqual "doesn't contain an exterior point" False contained
105 t = Tetrahedron { v0 = p0,
110 contained = contains_point t exterior_point
113 doesnt_contain_point3 :: Assertion
114 doesnt_contain_point3 =
115 assertEqual "doesn't contain an exterior point" False contained
119 t = Tetrahedron { v0 = p0,
124 contained = contains_point t exterior_point
127 doesnt_contain_point4 :: Assertion
128 doesnt_contain_point4 =
129 assertEqual "doesn't contain an exterior point" False contained
133 t = Tetrahedron { v0 = p0,
138 contained = contains_point t exterior_point
141 doesnt_contain_point5 :: Assertion
142 doesnt_contain_point5 =
143 assertEqual "doesn't contain an exterior point" False contained
147 t = Tetrahedron { v0 = p0,
152 contained = contains_point t exterior_point
155 -- | The barycentric coordinate of v0 with respect to itself should
157 prop_b0_v0_always_unity :: Tetrahedron -> Property
158 prop_b0_v0_always_unity t =
159 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
161 -- | The barycentric coordinate of v1 with respect to v0 should
163 prop_b0_v1_always_zero :: Tetrahedron -> Property
164 prop_b0_v1_always_zero t =
165 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
167 -- | The barycentric coordinate of v2 with respect to v0 should
169 prop_b0_v2_always_zero :: Tetrahedron -> Property
170 prop_b0_v2_always_zero t =
171 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
173 -- | The barycentric coordinate of v3 with respect to v0 should
175 prop_b0_v3_always_zero :: Tetrahedron -> Property
176 prop_b0_v3_always_zero t =
177 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
179 -- | The barycentric coordinate of v1 with respect to itself should
181 prop_b1_v1_always_unity :: Tetrahedron -> Property
182 prop_b1_v1_always_unity t =
183 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
185 -- | The barycentric coordinate of v0 with respect to v1 should
187 prop_b1_v0_always_zero :: Tetrahedron -> Property
188 prop_b1_v0_always_zero t =
189 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
191 -- | The barycentric coordinate of v2 with respect to v1 should
193 prop_b1_v2_always_zero :: Tetrahedron -> Property
194 prop_b1_v2_always_zero t =
195 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
197 -- | The barycentric coordinate of v3 with respect to v1 should
199 prop_b1_v3_always_zero :: Tetrahedron -> Property
200 prop_b1_v3_always_zero t =
201 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
203 -- | The barycentric coordinate of v2 with respect to itself should
205 prop_b2_v2_always_unity :: Tetrahedron -> Property
206 prop_b2_v2_always_unity t =
207 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
209 -- | The barycentric coordinate of v0 with respect to v2 should
211 prop_b2_v0_always_zero :: Tetrahedron -> Property
212 prop_b2_v0_always_zero t =
213 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
215 -- | The barycentric coordinate of v1 with respect to v2 should
217 prop_b2_v1_always_zero :: Tetrahedron -> Property
218 prop_b2_v1_always_zero t =
219 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
221 -- | The barycentric coordinate of v3 with respect to v2 should
223 prop_b2_v3_always_zero :: Tetrahedron -> Property
224 prop_b2_v3_always_zero t =
225 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
227 -- | The barycentric coordinate of v3 with respect to itself should
229 prop_b3_v3_always_unity :: Tetrahedron -> Property
230 prop_b3_v3_always_unity t =
231 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
233 -- | The barycentric coordinate of v0 with respect to v3 should
235 prop_b3_v0_always_zero :: Tetrahedron -> Property
236 prop_b3_v0_always_zero t =
237 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
239 -- | The barycentric coordinate of v1 with respect to v3 should
241 prop_b3_v1_always_zero :: Tetrahedron -> Property
242 prop_b3_v1_always_zero t =
243 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
245 -- | The barycentric coordinate of v2 with respect to v3 should
247 prop_b3_v2_always_zero :: Tetrahedron -> Property
248 prop_b3_v2_always_zero t =
249 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
252 -- | Used for convenience in the next few tests; not a test itself.
253 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
254 p t i j k l = (polynomial t) (xi t i j k l)
256 -- | Given in Sorokina and Zeilfelder, p. 78.
257 prop_c3000_identity :: Tetrahedron -> Property
258 prop_c3000_identity t =
260 c t 3 0 0 0 ~= p t 3 0 0 0
262 -- | Given in Sorokina and Zeilfelder, p. 78.
263 prop_c2100_identity :: Tetrahedron -> Property
264 prop_c2100_identity t =
266 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
268 term1 = (1/3)*(p t 0 3 0 0)
269 term2 = (5/6)*(p t 3 0 0 0)
270 term3 = 3*(p t 2 1 0 0)
271 term4 = (3/2)*(p t 1 2 0 0)
273 -- | Given in Sorokina and Zeilfelder, p. 78.
274 prop_c1110_identity :: Tetrahedron -> Property
275 prop_c1110_identity t =
277 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
279 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
280 term2 = (9/2)*(p t 1 1 1 0)
281 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
282 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
284 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
285 prop_x_rotation_doesnt_affect_front t =
288 fv0 = Tetrahedron.fv t
289 fv1 = rotate cwx (Tetrahedron.fv t)
293 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
294 prop_x_rotation_doesnt_affect_back t =
297 fv0 = Tetrahedron.fv t
298 fv1 = rotate cwx (Tetrahedron.fv t)
303 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
304 prop_y_rotation_doesnt_affect_left t =
307 fv0 = Tetrahedron.fv t
308 fv1 = rotate cwy (Tetrahedron.fv t)
312 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
313 prop_y_rotation_doesnt_affect_right t =
316 fv0 = Tetrahedron.fv t
317 fv1 = rotate cwy (Tetrahedron.fv t)
322 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
323 prop_z_rotation_doesnt_affect_down t =
326 fv0 = Tetrahedron.fv t
327 fv1 = rotate cwz (Tetrahedron.fv t)
332 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
333 prop_z_rotation_doesnt_affect_top t =
336 fv0 = Tetrahedron.fv t
337 fv1 = rotate cwz (Tetrahedron.fv t)
341 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
342 prop_swapping_vertices_doesnt_affect_coefficients1 t =
343 c t 0 0 1 2 == c t' 0 0 1 2
345 t' = t { v0 = (v1 t), v1 = (v0 t) }
347 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
348 prop_swapping_vertices_doesnt_affect_coefficients2 t =
349 c t 0 1 1 1 == c t' 0 1 1 1
351 t' = t { v2 = (v3 t), v3 = (v2 t) }
353 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
354 prop_swapping_vertices_doesnt_affect_coefficients3 t =
355 c t 2 1 0 0 == c t' 2 1 0 0
357 t' = t { v2 = (v3 t), v3 = (v2 t) }
359 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
360 prop_swapping_vertices_doesnt_affect_coefficients4 t =
361 c t 2 0 0 1 == c t' 2 0 0 1
363 t' = t { v0 = (v3 t), v3 = (v0 t) }