1 module Tests.Tetrahedron
4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
7 import Test.QuickCheck (Property, (==>))
13 import ThreeDimensional
18 -- | Check the volume of a particular tetrahedron (computed by hand)
19 -- and whether or not it contains a specific point chosen to be
20 -- outside of it. Its vertices are in clockwise order, so the volume
21 -- should be negative.
22 tetrahedron1_geometry_tests :: Test.Framework.Test
23 tetrahedron1_geometry_tests =
24 testGroup "tetrahedron1 geometry"
25 [ testCase "volume1" volume1,
26 testCase "doesn't contain point1" doesnt_contain_point1]
32 t = Tetrahedron { v0 = p0,
37 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,
77 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
81 contains_point1 :: Assertion
82 contains_point1 = assertEqual "contains an inner point" True contained
84 inner_point = (1, 0, 0.5)
85 contained = contains_point t inner_point
88 -- | Ensure that tetrahedra do not contain a particular point chosen to
89 -- be outside of them.
90 containment_tests :: Test.Framework.Test
92 testGroup "containment tests"
93 [ testCase "doesn't contain point2" doesnt_contain_point2,
94 testCase "doesn't contain point3" doesnt_contain_point3,
95 testCase "doesn't contain point4" doesnt_contain_point4,
96 testCase "doesn't contain point5" doesnt_contain_point5]
100 exterior_point = (0, 0, 0)
102 doesnt_contain_point2 :: Assertion
103 doesnt_contain_point2 =
104 assertEqual "doesn't contain an exterior point" False contained
108 t = Tetrahedron { v0 = p0,
113 precomputed_volume = 0,
115 contained = contains_point t exterior_point
118 doesnt_contain_point3 :: Assertion
119 doesnt_contain_point3 =
120 assertEqual "doesn't contain an exterior point" False contained
124 t = Tetrahedron { v0 = p0,
129 precomputed_volume = 0,
131 contained = contains_point t exterior_point
134 doesnt_contain_point4 :: Assertion
135 doesnt_contain_point4 =
136 assertEqual "doesn't contain an exterior point" False contained
140 t = Tetrahedron { v0 = p0,
145 precomputed_volume = 0,
147 contained = contains_point t exterior_point
150 doesnt_contain_point5 :: Assertion
151 doesnt_contain_point5 =
152 assertEqual "doesn't contain an exterior point" False contained
156 t = Tetrahedron { v0 = p0,
161 precomputed_volume = 0,
163 contained = contains_point t exterior_point
166 -- | The barycentric coordinate of v0 with respect to itself should
168 prop_b0_v0_always_unity :: Tetrahedron -> Property
169 prop_b0_v0_always_unity t =
170 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
172 -- | The barycentric coordinate of v1 with respect to v0 should
174 prop_b0_v1_always_zero :: Tetrahedron -> Property
175 prop_b0_v1_always_zero t =
176 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
178 -- | The barycentric coordinate of v2 with respect to v0 should
180 prop_b0_v2_always_zero :: Tetrahedron -> Property
181 prop_b0_v2_always_zero t =
182 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
184 -- | The barycentric coordinate of v3 with respect to v0 should
186 prop_b0_v3_always_zero :: Tetrahedron -> Property
187 prop_b0_v3_always_zero t =
188 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
190 -- | The barycentric coordinate of v1 with respect to itself should
192 prop_b1_v1_always_unity :: Tetrahedron -> Property
193 prop_b1_v1_always_unity t =
194 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
196 -- | The barycentric coordinate of v0 with respect to v1 should
198 prop_b1_v0_always_zero :: Tetrahedron -> Property
199 prop_b1_v0_always_zero t =
200 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
202 -- | The barycentric coordinate of v2 with respect to v1 should
204 prop_b1_v2_always_zero :: Tetrahedron -> Property
205 prop_b1_v2_always_zero t =
206 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
208 -- | The barycentric coordinate of v3 with respect to v1 should
210 prop_b1_v3_always_zero :: Tetrahedron -> Property
211 prop_b1_v3_always_zero t =
212 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
214 -- | The barycentric coordinate of v2 with respect to itself should
216 prop_b2_v2_always_unity :: Tetrahedron -> Property
217 prop_b2_v2_always_unity t =
218 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
220 -- | The barycentric coordinate of v0 with respect to v2 should
222 prop_b2_v0_always_zero :: Tetrahedron -> Property
223 prop_b2_v0_always_zero t =
224 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
226 -- | The barycentric coordinate of v1 with respect to v2 should
228 prop_b2_v1_always_zero :: Tetrahedron -> Property
229 prop_b2_v1_always_zero t =
230 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
232 -- | The barycentric coordinate of v3 with respect to v2 should
234 prop_b2_v3_always_zero :: Tetrahedron -> Property
235 prop_b2_v3_always_zero t =
236 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
238 -- | The barycentric coordinate of v3 with respect to itself should
240 prop_b3_v3_always_unity :: Tetrahedron -> Property
241 prop_b3_v3_always_unity t =
242 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
244 -- | The barycentric coordinate of v0 with respect to v3 should
246 prop_b3_v0_always_zero :: Tetrahedron -> Property
247 prop_b3_v0_always_zero t =
248 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
250 -- | The barycentric coordinate of v1 with respect to v3 should
252 prop_b3_v1_always_zero :: Tetrahedron -> Property
253 prop_b3_v1_always_zero t =
254 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
256 -- | The barycentric coordinate of v2 with respect to v3 should
258 prop_b3_v2_always_zero :: Tetrahedron -> Property
259 prop_b3_v2_always_zero t =
260 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
263 -- | Used for convenience in the next few tests; not a test itself.
264 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
265 p t i j k l = (polynomial t) (xi t i j k l)
267 -- | Given in Sorokina and Zeilfelder, p. 78.
268 prop_c3000_identity :: Tetrahedron -> Property
269 prop_c3000_identity t =
271 c t 3 0 0 0 ~= p t 3 0 0 0
273 -- | Given in Sorokina and Zeilfelder, p. 78.
274 prop_c2100_identity :: Tetrahedron -> Property
275 prop_c2100_identity t =
277 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
279 term1 = (1/3)*(p t 0 3 0 0)
280 term2 = (5/6)*(p t 3 0 0 0)
281 term3 = 3*(p t 2 1 0 0)
282 term4 = (3/2)*(p t 1 2 0 0)
284 -- | Given in Sorokina and Zeilfelder, p. 78.
285 prop_c1110_identity :: Tetrahedron -> Property
286 prop_c1110_identity t =
288 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
290 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
291 term2 = (9/2)*(p t 1 1 1 0)
292 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
293 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
296 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
297 prop_swapping_vertices_doesnt_affect_coefficients1 t =
298 c t 0 0 1 2 == c t' 0 0 1 2
300 t' = t { v0 = (v1 t), v1 = (v0 t) }
302 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
303 prop_swapping_vertices_doesnt_affect_coefficients2 t =
304 c t 0 1 1 1 == c t' 0 1 1 1
306 t' = t { v2 = (v3 t), v3 = (v2 t) }
308 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
309 prop_swapping_vertices_doesnt_affect_coefficients3 t =
310 c t 2 1 0 0 == c t' 2 1 0 0
312 t' = t { v2 = (v3 t), v3 = (v2 t) }
314 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
315 prop_swapping_vertices_doesnt_affect_coefficients4 t =
316 c t 2 0 0 1 == c t' 2 0 0 1
318 t' = t { v0 = (v3 t), v3 = (v0 t) }