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 }
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,
72 precomputed_volume = 0 }
75 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
79 contains_point1 :: Assertion
80 contains_point1 = assertEqual "contains an inner point" True contained
82 inner_point = (1, 0, 0.5)
83 contained = contains_point t inner_point
86 -- | Ensure that tetrahedra do not contain a particular point chosen to
87 -- be outside of them.
88 containment_tests :: Test.Framework.Test
90 testGroup "containment tests"
91 [ testCase "doesn't contain point2" doesnt_contain_point2,
92 testCase "doesn't contain point3" doesnt_contain_point3,
93 testCase "doesn't contain point4" doesnt_contain_point4,
94 testCase "doesn't contain point5" doesnt_contain_point5]
98 exterior_point = (0, 0, 0)
100 doesnt_contain_point2 :: Assertion
101 doesnt_contain_point2 =
102 assertEqual "doesn't contain an exterior point" False contained
106 t = Tetrahedron { v0 = p0,
111 precomputed_volume = 0 }
112 contained = contains_point t exterior_point
115 doesnt_contain_point3 :: Assertion
116 doesnt_contain_point3 =
117 assertEqual "doesn't contain an exterior point" False contained
121 t = Tetrahedron { v0 = p0,
126 precomputed_volume = 0 }
127 contained = contains_point t exterior_point
130 doesnt_contain_point4 :: Assertion
131 doesnt_contain_point4 =
132 assertEqual "doesn't contain an exterior point" False contained
136 t = Tetrahedron { v0 = p0,
141 precomputed_volume = 0 }
142 contained = contains_point t exterior_point
145 doesnt_contain_point5 :: Assertion
146 doesnt_contain_point5 =
147 assertEqual "doesn't contain an exterior point" False contained
151 t = Tetrahedron { v0 = p0,
156 precomputed_volume = 0 }
157 contained = contains_point t exterior_point
160 -- | The barycentric coordinate of v0 with respect to itself should
162 prop_b0_v0_always_unity :: Tetrahedron -> Property
163 prop_b0_v0_always_unity t =
164 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
166 -- | The barycentric coordinate of v1 with respect to v0 should
168 prop_b0_v1_always_zero :: Tetrahedron -> Property
169 prop_b0_v1_always_zero t =
170 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
172 -- | The barycentric coordinate of v2 with respect to v0 should
174 prop_b0_v2_always_zero :: Tetrahedron -> Property
175 prop_b0_v2_always_zero t =
176 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
178 -- | The barycentric coordinate of v3 with respect to v0 should
180 prop_b0_v3_always_zero :: Tetrahedron -> Property
181 prop_b0_v3_always_zero t =
182 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
184 -- | The barycentric coordinate of v1 with respect to itself should
186 prop_b1_v1_always_unity :: Tetrahedron -> Property
187 prop_b1_v1_always_unity t =
188 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
190 -- | The barycentric coordinate of v0 with respect to v1 should
192 prop_b1_v0_always_zero :: Tetrahedron -> Property
193 prop_b1_v0_always_zero t =
194 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
196 -- | The barycentric coordinate of v2 with respect to v1 should
198 prop_b1_v2_always_zero :: Tetrahedron -> Property
199 prop_b1_v2_always_zero t =
200 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
202 -- | The barycentric coordinate of v3 with respect to v1 should
204 prop_b1_v3_always_zero :: Tetrahedron -> Property
205 prop_b1_v3_always_zero t =
206 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
208 -- | The barycentric coordinate of v2 with respect to itself should
210 prop_b2_v2_always_unity :: Tetrahedron -> Property
211 prop_b2_v2_always_unity t =
212 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
214 -- | The barycentric coordinate of v0 with respect to v2 should
216 prop_b2_v0_always_zero :: Tetrahedron -> Property
217 prop_b2_v0_always_zero t =
218 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
220 -- | The barycentric coordinate of v1 with respect to v2 should
222 prop_b2_v1_always_zero :: Tetrahedron -> Property
223 prop_b2_v1_always_zero t =
224 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
226 -- | The barycentric coordinate of v3 with respect to v2 should
228 prop_b2_v3_always_zero :: Tetrahedron -> Property
229 prop_b2_v3_always_zero t =
230 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
232 -- | The barycentric coordinate of v3 with respect to itself should
234 prop_b3_v3_always_unity :: Tetrahedron -> Property
235 prop_b3_v3_always_unity t =
236 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
238 -- | The barycentric coordinate of v0 with respect to v3 should
240 prop_b3_v0_always_zero :: Tetrahedron -> Property
241 prop_b3_v0_always_zero t =
242 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
244 -- | The barycentric coordinate of v1 with respect to v3 should
246 prop_b3_v1_always_zero :: Tetrahedron -> Property
247 prop_b3_v1_always_zero t =
248 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
250 -- | The barycentric coordinate of v2 with respect to v3 should
252 prop_b3_v2_always_zero :: Tetrahedron -> Property
253 prop_b3_v2_always_zero t =
254 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
257 -- | Used for convenience in the next few tests; not a test itself.
258 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
259 p t i j k l = (polynomial t) (xi t i j k l)
261 -- | Given in Sorokina and Zeilfelder, p. 78.
262 prop_c3000_identity :: Tetrahedron -> Property
263 prop_c3000_identity t =
265 c t 3 0 0 0 ~= p t 3 0 0 0
267 -- | Given in Sorokina and Zeilfelder, p. 78.
268 prop_c2100_identity :: Tetrahedron -> Property
269 prop_c2100_identity t =
271 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
273 term1 = (1/3)*(p t 0 3 0 0)
274 term2 = (5/6)*(p t 3 0 0 0)
275 term3 = 3*(p t 2 1 0 0)
276 term4 = (3/2)*(p t 1 2 0 0)
278 -- | Given in Sorokina and Zeilfelder, p. 78.
279 prop_c1110_identity :: Tetrahedron -> Property
280 prop_c1110_identity t =
282 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
284 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
285 term2 = (9/2)*(p t 1 1 1 0)
286 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
287 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
290 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
291 prop_swapping_vertices_doesnt_affect_coefficients1 t =
292 c t 0 0 1 2 == c t' 0 0 1 2
294 t' = t { v0 = (v1 t), v1 = (v0 t) }
296 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
297 prop_swapping_vertices_doesnt_affect_coefficients2 t =
298 c t 0 1 1 1 == c t' 0 1 1 1
300 t' = t { v2 = (v3 t), v3 = (v2 t) }
302 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
303 prop_swapping_vertices_doesnt_affect_coefficients3 t =
304 c t 2 1 0 0 == c t' 2 1 0 0
306 t' = t { v2 = (v3 t), v3 = (v2 t) }
308 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
309 prop_swapping_vertices_doesnt_affect_coefficients4 t =
310 c t 2 0 0 1 == c t' 2 0 0 1
312 t' = t { v0 = (v3 t), v3 = (v0 t) }