1 module Tests.Tetrahedron
11 import ThreeDimensional
13 instance Arbitrary Tetrahedron where
15 rnd_c0 <- arbitrary :: Gen Cube
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 return (Tetrahedron rnd_c0 rnd_v0 rnd_v1 rnd_v2 rnd_v3)
22 almost_equals :: Double -> Double -> Bool
23 almost_equals x y = (abs (x - y)) < 0.0001
25 (~=) :: Double -> Double -> Bool
31 -- Since p0, p1, p2 are in clockwise order, we expect the volume here
35 TestCase $ assertEqual "volume is correct" True (vol ~= (-1/3))
41 t = Tetrahedron { cube = empty_cube,
49 -- Now, p0, p1, and p2 are in counter-clockwise order. The volume
50 -- should therefore be positive.
53 TestCase $ assertEqual "volume is correct" True (vol ~= (1/3))
59 t = Tetrahedron { cube = empty_cube,
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 { cube = empty_cube,
82 test_doesnt_contain_point1 :: Test
83 test_doesnt_contain_point1 =
84 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
90 exterior_point = (5, 2, -9.0212)
92 t = Tetrahedron { cube = c_empty,
99 test_doesnt_contain_point2 :: Test
100 test_doesnt_contain_point2 =
101 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
107 exterior_point = (0, 0, 0)
109 t = Tetrahedron { cube = c_empty,
115 test_doesnt_contain_point3 :: Test
116 test_doesnt_contain_point3 =
117 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
123 exterior_point = (0, 0, 0)
125 t = Tetrahedron { cube = c_empty,
131 test_doesnt_contain_point4 :: Test
132 test_doesnt_contain_point4 =
133 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
139 exterior_point = (0, 0, 0)
141 t = Tetrahedron { cube = c_empty,
147 test_doesnt_contain_point5 :: Test
148 test_doesnt_contain_point5 =
149 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
155 exterior_point = (0, 0, 0)
157 t = Tetrahedron { cube = c_empty,
163 tetrahedron_tests :: [Test]
164 tetrahedron_tests = [test_volume1,
166 test_contains_point1,
167 test_doesnt_contain_point1,
168 test_doesnt_contain_point2,
169 test_doesnt_contain_point3,
170 test_doesnt_contain_point4,
171 test_doesnt_contain_point5 ]
173 prop_b0_v0_always_unity :: Tetrahedron -> Property
174 prop_b0_v0_always_unity t =
175 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
177 prop_b0_v1_always_zero :: Tetrahedron -> Property
178 prop_b0_v1_always_zero t =
179 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
181 prop_b0_v2_always_zero :: Tetrahedron -> Property
182 prop_b0_v2_always_zero t =
183 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
185 prop_b0_v3_always_zero :: Tetrahedron -> Property
186 prop_b0_v3_always_zero t =
187 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
189 prop_b1_v1_always_unity :: Tetrahedron -> Property
190 prop_b1_v1_always_unity t =
191 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
193 prop_b1_v0_always_zero :: Tetrahedron -> Property
194 prop_b1_v0_always_zero t =
195 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
197 prop_b1_v2_always_zero :: Tetrahedron -> Property
198 prop_b1_v2_always_zero t =
199 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
201 prop_b1_v3_always_zero :: Tetrahedron -> Property
202 prop_b1_v3_always_zero t =
203 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
205 prop_b2_v2_always_unity :: Tetrahedron -> Property
206 prop_b2_v2_always_unity t =
207 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
209 prop_b2_v0_always_zero :: Tetrahedron -> Property
210 prop_b2_v0_always_zero t =
211 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
213 prop_b2_v1_always_zero :: Tetrahedron -> Property
214 prop_b2_v1_always_zero t =
215 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
217 prop_b2_v3_always_zero :: Tetrahedron -> Property
218 prop_b2_v3_always_zero t =
219 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
221 prop_b3_v3_always_unity :: Tetrahedron -> Property
222 prop_b3_v3_always_unity t =
223 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
225 prop_b3_v0_always_zero :: Tetrahedron -> Property
226 prop_b3_v0_always_zero t =
227 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
229 prop_b3_v1_always_zero :: Tetrahedron -> Property
230 prop_b3_v1_always_zero t =
231 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
233 prop_b3_v2_always_zero :: Tetrahedron -> Property
234 prop_b3_v2_always_zero t =
235 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
238 -- Used for convenience in the next few tests.
239 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
240 p t i j k l = (polynomial t) (xi t i j k l)
242 -- | Given in Sorokina and Zeilfelder, p. 78.
243 prop_c3000_identity :: Tetrahedron -> Property
244 prop_c3000_identity t =
246 c t 3 0 0 0 ~= p t 3 0 0 0
248 -- | Given in Sorokina and Zeilfelder, p. 78.
249 prop_c2100_identity :: Tetrahedron -> Property
250 prop_c2100_identity t =
252 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
254 term1 = (1/3)*(p t 0 3 0 0)
255 term2 = (5/6)*(p t 3 0 0 0)
256 term3 = 3*(p t 2 1 0 0)
257 term4 = (3/2)*(p t 1 2 0 0)
259 -- | Given in Sorokina and Zeilfelder, p. 78.
260 prop_c1110_identity :: Tetrahedron -> Property
261 prop_c1110_identity t =
263 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
265 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
266 term2 = (9/2)*(p t 1 1 1 0)
267 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
268 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))