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.
32 TestCase $ 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.
51 TestCase $ 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 :: Test
68 test_contains_point1 =
69 TestCase $ 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 :: Test
86 test_doesnt_contain_point1 =
87 TestCase $ 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 :: Test
104 test_doesnt_contain_point2 =
105 TestCase $ 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 :: Test
122 test_doesnt_contain_point3 =
123 TestCase $ 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 :: Test
140 test_doesnt_contain_point4 =
141 TestCase $ 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 :: Test
158 test_doesnt_contain_point5 =
159 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
165 exterior_point = (0, 0, 0)
166 t = Tetrahedron { v0 = p0,
172 -- | A list of all HUnit tests defined in this module.
173 tetrahedron_tests :: [Test]
174 tetrahedron_tests = [test_volume1,
176 test_contains_point1,
177 test_doesnt_contain_point1,
178 test_doesnt_contain_point2,
179 test_doesnt_contain_point3,
180 test_doesnt_contain_point4,
181 test_doesnt_contain_point5 ]
184 -- | The barycentric coordinate of v0 with respect to itself should
186 prop_b0_v0_always_unity :: Tetrahedron -> Property
187 prop_b0_v0_always_unity t =
188 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
190 -- | The barycentric coordinate of v1 with respect to v0 should
192 prop_b0_v1_always_zero :: Tetrahedron -> Property
193 prop_b0_v1_always_zero t =
194 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
196 -- | The barycentric coordinate of v2 with respect to v0 should
198 prop_b0_v2_always_zero :: Tetrahedron -> Property
199 prop_b0_v2_always_zero t =
200 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
202 -- | The barycentric coordinate of v3 with respect to v0 should
204 prop_b0_v3_always_zero :: Tetrahedron -> Property
205 prop_b0_v3_always_zero t =
206 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
208 -- | The barycentric coordinate of v1 with respect to itself should
210 prop_b1_v1_always_unity :: Tetrahedron -> Property
211 prop_b1_v1_always_unity t =
212 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
214 -- | The barycentric coordinate of v0 with respect to v1 should
216 prop_b1_v0_always_zero :: Tetrahedron -> Property
217 prop_b1_v0_always_zero t =
218 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
220 -- | The barycentric coordinate of v2 with respect to v1 should
222 prop_b1_v2_always_zero :: Tetrahedron -> Property
223 prop_b1_v2_always_zero t =
224 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
226 -- | The barycentric coordinate of v3 with respect to v1 should
228 prop_b1_v3_always_zero :: Tetrahedron -> Property
229 prop_b1_v3_always_zero t =
230 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
232 -- | The barycentric coordinate of v2 with respect to itself should
234 prop_b2_v2_always_unity :: Tetrahedron -> Property
235 prop_b2_v2_always_unity t =
236 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
238 -- | The barycentric coordinate of v0 with respect to v2 should
240 prop_b2_v0_always_zero :: Tetrahedron -> Property
241 prop_b2_v0_always_zero t =
242 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
244 -- | The barycentric coordinate of v1 with respect to v2 should
246 prop_b2_v1_always_zero :: Tetrahedron -> Property
247 prop_b2_v1_always_zero t =
248 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
250 -- | The barycentric coordinate of v3 with respect to v2 should
252 prop_b2_v3_always_zero :: Tetrahedron -> Property
253 prop_b2_v3_always_zero t =
254 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
256 -- | The barycentric coordinate of v3 with respect to itself should
258 prop_b3_v3_always_unity :: Tetrahedron -> Property
259 prop_b3_v3_always_unity t =
260 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
262 -- | The barycentric coordinate of v0 with respect to v3 should
264 prop_b3_v0_always_zero :: Tetrahedron -> Property
265 prop_b3_v0_always_zero t =
266 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
268 -- | The barycentric coordinate of v1 with respect to v3 should
270 prop_b3_v1_always_zero :: Tetrahedron -> Property
271 prop_b3_v1_always_zero t =
272 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
274 -- | The barycentric coordinate of v2 with respect to v3 should
276 prop_b3_v2_always_zero :: Tetrahedron -> Property
277 prop_b3_v2_always_zero t =
278 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
281 -- | Used for convenience in the next few tests; not a test itself.
282 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
283 p t i j k l = (polynomial t) (xi t i j k l)
285 -- | Given in Sorokina and Zeilfelder, p. 78.
286 prop_c3000_identity :: Tetrahedron -> Property
287 prop_c3000_identity t =
289 c t 3 0 0 0 ~= p t 3 0 0 0
291 -- | Given in Sorokina and Zeilfelder, p. 78.
292 prop_c2100_identity :: Tetrahedron -> Property
293 prop_c2100_identity t =
295 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
297 term1 = (1/3)*(p t 0 3 0 0)
298 term2 = (5/6)*(p t 3 0 0 0)
299 term3 = 3*(p t 2 1 0 0)
300 term4 = (3/2)*(p t 1 2 0 0)
302 -- | Given in Sorokina and Zeilfelder, p. 78.
303 prop_c1110_identity :: Tetrahedron -> Property
304 prop_c1110_identity t =
306 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
308 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
309 term2 = (9/2)*(p t 1 1 1 0)
310 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
311 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
313 prop_x_rotation_doesnt_affect_front :: Tetrahedron -> Bool
314 prop_x_rotation_doesnt_affect_front t =
317 fv0 = Tetrahedron.fv t
318 fv1 = rotate (Tetrahedron.fv t) cwx
322 prop_x_rotation_doesnt_affect_back :: Tetrahedron -> Bool
323 prop_x_rotation_doesnt_affect_back t =
326 fv0 = Tetrahedron.fv t
327 fv1 = rotate (Tetrahedron.fv t) cwx
332 prop_y_rotation_doesnt_affect_left :: Tetrahedron -> Bool
333 prop_y_rotation_doesnt_affect_left t =
336 fv0 = Tetrahedron.fv t
337 fv1 = rotate (Tetrahedron.fv t) cwy
341 prop_y_rotation_doesnt_affect_right :: Tetrahedron -> Bool
342 prop_y_rotation_doesnt_affect_right t =
345 fv0 = Tetrahedron.fv t
346 fv1 = rotate (Tetrahedron.fv t) cwy
351 prop_z_rotation_doesnt_affect_down :: Tetrahedron -> Bool
352 prop_z_rotation_doesnt_affect_down t =
355 fv0 = Tetrahedron.fv t
356 fv1 = rotate (Tetrahedron.fv t) cwz
361 prop_z_rotation_doesnt_affect_top :: Tetrahedron -> Bool
362 prop_z_rotation_doesnt_affect_top t =
365 fv0 = Tetrahedron.fv t
366 fv1 = rotate (Tetrahedron.fv t) cwz