1 module Tests.Tetrahedron
12 import ThreeDimensional
14 instance Arbitrary Tetrahedron where
16 rnd_c0 <- arbitrary :: Gen Cube
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 return (Tetrahedron rnd_c0 rnd_v0 rnd_v1 rnd_v2 rnd_v3)
25 -- Since p0, p1, p2 are in clockwise order, we expect the volume here
29 TestCase $ assertEqual "volume is correct" True (vol ~= (-1/3))
35 t = Tetrahedron { cube = empty_cube,
43 -- Now, p0, p1, and p2 are in counter-clockwise order. The volume
44 -- should therefore be positive.
47 TestCase $ assertEqual "volume is correct" True (vol ~= (1/3))
53 t = Tetrahedron { cube = empty_cube,
60 test_contains_point1 :: Test
61 test_contains_point1 =
62 TestCase $ assertEqual "contains an inner point" True (contains_point t inner_point)
68 inner_point = (1, 0, 0.5)
69 t = Tetrahedron { cube = empty_cube,
76 test_doesnt_contain_point1 :: Test
77 test_doesnt_contain_point1 =
78 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
84 exterior_point = (5, 2, -9.0212)
86 t = Tetrahedron { cube = c_empty,
93 test_doesnt_contain_point2 :: Test
94 test_doesnt_contain_point2 =
95 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
101 exterior_point = (0, 0, 0)
103 t = Tetrahedron { cube = c_empty,
109 test_doesnt_contain_point3 :: Test
110 test_doesnt_contain_point3 =
111 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
117 exterior_point = (0, 0, 0)
119 t = Tetrahedron { cube = c_empty,
125 test_doesnt_contain_point4 :: Test
126 test_doesnt_contain_point4 =
127 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
133 exterior_point = (0, 0, 0)
135 t = Tetrahedron { cube = c_empty,
141 test_doesnt_contain_point5 :: Test
142 test_doesnt_contain_point5 =
143 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
149 exterior_point = (0, 0, 0)
151 t = Tetrahedron { cube = c_empty,
157 tetrahedron_tests :: [Test]
158 tetrahedron_tests = [test_volume1,
160 test_contains_point1,
161 test_doesnt_contain_point1,
162 test_doesnt_contain_point2,
163 test_doesnt_contain_point3,
164 test_doesnt_contain_point4,
165 test_doesnt_contain_point5 ]
167 prop_b0_v0_always_unity :: Tetrahedron -> Property
168 prop_b0_v0_always_unity t =
169 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
171 prop_b0_v1_always_zero :: Tetrahedron -> Property
172 prop_b0_v1_always_zero t =
173 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
175 prop_b0_v2_always_zero :: Tetrahedron -> Property
176 prop_b0_v2_always_zero t =
177 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
179 prop_b0_v3_always_zero :: Tetrahedron -> Property
180 prop_b0_v3_always_zero t =
181 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
183 prop_b1_v1_always_unity :: Tetrahedron -> Property
184 prop_b1_v1_always_unity t =
185 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
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 prop_b1_v2_always_zero :: Tetrahedron -> Property
192 prop_b1_v2_always_zero t =
193 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
195 prop_b1_v3_always_zero :: Tetrahedron -> Property
196 prop_b1_v3_always_zero t =
197 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
199 prop_b2_v2_always_unity :: Tetrahedron -> Property
200 prop_b2_v2_always_unity t =
201 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
203 prop_b2_v0_always_zero :: Tetrahedron -> Property
204 prop_b2_v0_always_zero t =
205 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
207 prop_b2_v1_always_zero :: Tetrahedron -> Property
208 prop_b2_v1_always_zero t =
209 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
211 prop_b2_v3_always_zero :: Tetrahedron -> Property
212 prop_b2_v3_always_zero t =
213 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
215 prop_b3_v3_always_unity :: Tetrahedron -> Property
216 prop_b3_v3_always_unity t =
217 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
219 prop_b3_v0_always_zero :: Tetrahedron -> Property
220 prop_b3_v0_always_zero t =
221 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
223 prop_b3_v1_always_zero :: Tetrahedron -> Property
224 prop_b3_v1_always_zero t =
225 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
227 prop_b3_v2_always_zero :: Tetrahedron -> Property
228 prop_b3_v2_always_zero t =
229 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
232 -- Used for convenience in the next few tests.
233 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
234 p t i j k l = (polynomial t) (xi t i j k l)
236 -- | Given in Sorokina and Zeilfelder, p. 78.
237 prop_c3000_identity :: Tetrahedron -> Property
238 prop_c3000_identity t =
240 c t 3 0 0 0 ~= p t 3 0 0 0
242 -- | Given in Sorokina and Zeilfelder, p. 78.
243 prop_c2100_identity :: Tetrahedron -> Property
244 prop_c2100_identity t =
246 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
248 term1 = (1/3)*(p t 0 3 0 0)
249 term2 = (5/6)*(p t 3 0 0 0)
250 term3 = 3*(p t 2 1 0 0)
251 term4 = (3/2)*(p t 1 2 0 0)
253 -- | Given in Sorokina and Zeilfelder, p. 78.
254 prop_c1110_identity :: Tetrahedron -> Property
255 prop_c1110_identity t =
257 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
259 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
260 term2 = (9/2)*(p t 1 1 1 0)
261 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
262 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))