1 module Tests.Tetrahedron
10 import Tests.FunctionValues()
12 import ThreeDimensional
14 instance Arbitrary Tetrahedron where
16 rnd_v0 <- arbitrary :: Gen Point
17 rnd_v1 <- arbitrary :: Gen Point
18 rnd_v2 <- arbitrary :: Gen Point
19 rnd_v3 <- arbitrary :: Gen Point
20 rnd_fv <- arbitrary :: Gen FunctionValues
21 return (Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3)
26 -- | Check the volume of a particular tetrahedron against the value
27 -- computed by hand. Its vertices are in clockwise order, so the
28 -- volume should be negative.
31 TestCase $ assertEqual "volume is correct" True (vol ~= (-1/3))
37 t = Tetrahedron { v0 = p0,
45 -- | Check the volume of a particular tetrahedron against the value
46 -- computed by hand. Its vertices are in counter-clockwise order, so
47 -- the volume should be positive.
50 TestCase $ assertEqual "volume is correct" True (vol ~= (1/3))
56 t = Tetrahedron { v0 = p0,
64 -- | Ensure that a tetrahedron contains a particular point chosen to
66 test_contains_point1 :: Test
67 test_contains_point1 =
68 TestCase $ assertEqual "contains an inner point" True (contains_point t inner_point)
74 inner_point = (1, 0, 0.5)
75 t = Tetrahedron { v0 = p0,
82 -- | Ensure that a tetrahedron does not contain a particular point chosen to
83 -- be outside of it (first test).
84 test_doesnt_contain_point1 :: Test
85 test_doesnt_contain_point1 =
86 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
92 exterior_point = (5, 2, -9.0212)
93 t = Tetrahedron { v0 = p0,
100 -- | Ensure that a tetrahedron does not contain a particular point chosen to
101 -- be outside of it (second test).
102 test_doesnt_contain_point2 :: Test
103 test_doesnt_contain_point2 =
104 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
110 exterior_point = (0, 0, 0)
111 t = Tetrahedron { v0 = p0,
118 -- | Ensure that a tetrahedron does not contain a particular point chosen to
119 -- be outside of it (third test).
120 test_doesnt_contain_point3 :: Test
121 test_doesnt_contain_point3 =
122 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
128 exterior_point = (0, 0, 0)
129 t = Tetrahedron { v0 = p0,
136 -- | Ensure that a tetrahedron does not contain a particular point chosen to
137 -- be outside of it (fourth test).
138 test_doesnt_contain_point4 :: Test
139 test_doesnt_contain_point4 =
140 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
146 exterior_point = (0, 0, 0)
147 t = Tetrahedron { v0 = p0,
154 -- | Ensure that a tetrahedron does not contain a particular point chosen to
155 -- be outside of it (fifth test).
156 test_doesnt_contain_point5 :: Test
157 test_doesnt_contain_point5 =
158 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
164 exterior_point = (0, 0, 0)
165 t = Tetrahedron { v0 = p0,
171 -- | A list of all HUnit tests defined in this module.
172 tetrahedron_tests :: [Test]
173 tetrahedron_tests = [test_volume1,
175 test_contains_point1,
176 test_doesnt_contain_point1,
177 test_doesnt_contain_point2,
178 test_doesnt_contain_point3,
179 test_doesnt_contain_point4,
180 test_doesnt_contain_point5 ]
183 -- | The barycentric coordinate of v0 with respect to itself should
185 prop_b0_v0_always_unity :: Tetrahedron -> Property
186 prop_b0_v0_always_unity t =
187 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
189 -- | The barycentric coordinate of v1 with respect to v0 should
191 prop_b0_v1_always_zero :: Tetrahedron -> Property
192 prop_b0_v1_always_zero t =
193 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
195 -- | The barycentric coordinate of v2 with respect to v0 should
197 prop_b0_v2_always_zero :: Tetrahedron -> Property
198 prop_b0_v2_always_zero t =
199 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
201 -- | The barycentric coordinate of v3 with respect to v0 should
203 prop_b0_v3_always_zero :: Tetrahedron -> Property
204 prop_b0_v3_always_zero t =
205 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
207 -- | The barycentric coordinate of v1 with respect to itself should
209 prop_b1_v1_always_unity :: Tetrahedron -> Property
210 prop_b1_v1_always_unity t =
211 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
213 -- | The barycentric coordinate of v0 with respect to v1 should
215 prop_b1_v0_always_zero :: Tetrahedron -> Property
216 prop_b1_v0_always_zero t =
217 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
219 -- | The barycentric coordinate of v2 with respect to v1 should
221 prop_b1_v2_always_zero :: Tetrahedron -> Property
222 prop_b1_v2_always_zero t =
223 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
225 -- | The barycentric coordinate of v3 with respect to v1 should
227 prop_b1_v3_always_zero :: Tetrahedron -> Property
228 prop_b1_v3_always_zero t =
229 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
231 -- | The barycentric coordinate of v2 with respect to itself should
233 prop_b2_v2_always_unity :: Tetrahedron -> Property
234 prop_b2_v2_always_unity t =
235 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
237 -- | The barycentric coordinate of v0 with respect to v2 should
239 prop_b2_v0_always_zero :: Tetrahedron -> Property
240 prop_b2_v0_always_zero t =
241 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
243 -- | The barycentric coordinate of v1 with respect to v2 should
245 prop_b2_v1_always_zero :: Tetrahedron -> Property
246 prop_b2_v1_always_zero t =
247 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
249 -- | The barycentric coordinate of v3 with respect to v2 should
251 prop_b2_v3_always_zero :: Tetrahedron -> Property
252 prop_b2_v3_always_zero t =
253 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
255 -- | The barycentric coordinate of v3 with respect to itself should
257 prop_b3_v3_always_unity :: Tetrahedron -> Property
258 prop_b3_v3_always_unity t =
259 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
261 -- | The barycentric coordinate of v0 with respect to v3 should
263 prop_b3_v0_always_zero :: Tetrahedron -> Property
264 prop_b3_v0_always_zero t =
265 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
267 -- | The barycentric coordinate of v1 with respect to v3 should
269 prop_b3_v1_always_zero :: Tetrahedron -> Property
270 prop_b3_v1_always_zero t =
271 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
273 -- | The barycentric coordinate of v2 with respect to v3 should
275 prop_b3_v2_always_zero :: Tetrahedron -> Property
276 prop_b3_v2_always_zero t =
277 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
280 -- | Used for convenience in the next few tests; not a test itself.
281 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
282 p t i j k l = (polynomial t) (xi t i j k l)
284 -- | Given in Sorokina and Zeilfelder, p. 78.
285 prop_c3000_identity :: Tetrahedron -> Property
286 prop_c3000_identity t =
288 c t 3 0 0 0 ~= p t 3 0 0 0
290 -- | Given in Sorokina and Zeilfelder, p. 78.
291 prop_c2100_identity :: Tetrahedron -> Property
292 prop_c2100_identity t =
294 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
296 term1 = (1/3)*(p t 0 3 0 0)
297 term2 = (5/6)*(p t 3 0 0 0)
298 term3 = 3*(p t 2 1 0 0)
299 term4 = (3/2)*(p t 1 2 0 0)
301 -- | Given in Sorokina and Zeilfelder, p. 78.
302 prop_c1110_identity :: Tetrahedron -> Property
303 prop_c1110_identity t =
305 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
307 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
308 term2 = (9/2)*(p t 1 1 1 0)
309 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
310 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))