1 module Tests.Tetrahedron
12 import Tests.FunctionValues()
14 import ThreeDimensional
16 instance Arbitrary Tetrahedron where
18 rnd_v0 <- arbitrary :: Gen Point
19 rnd_v1 <- arbitrary :: Gen Point
20 rnd_v2 <- arbitrary :: Gen Point
21 rnd_v3 <- arbitrary :: Gen Point
22 rnd_fv <- arbitrary :: Gen FunctionValues
23 return (Tetrahedron rnd_fv rnd_v0 rnd_v1 rnd_v2 rnd_v3)
27 -- Since p0, p1, p2 are in clockwise order, we expect the volume here
31 TestCase $ assertEqual "volume is correct" True (vol ~= (-1/3))
37 t = Tetrahedron { v0 = p0,
45 -- Now, p0, p1, and p2 are in counter-clockwise order. The volume
46 -- should therefore be positive.
49 TestCase $ assertEqual "volume is correct" True (vol ~= (1/3))
55 t = Tetrahedron { v0 = p0,
62 test_contains_point1 :: Test
63 test_contains_point1 =
64 TestCase $ assertEqual "contains an inner point" True (contains_point t inner_point)
70 inner_point = (1, 0, 0.5)
71 t = Tetrahedron { v0 = p0,
78 test_doesnt_contain_point1 :: Test
79 test_doesnt_contain_point1 =
80 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
86 exterior_point = (5, 2, -9.0212)
87 t = Tetrahedron { v0 = p0,
94 test_doesnt_contain_point2 :: Test
95 test_doesnt_contain_point2 =
96 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
102 exterior_point = (0, 0, 0)
103 t = Tetrahedron { v0 = p0,
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)
118 t = Tetrahedron { v0 = p0,
124 test_doesnt_contain_point4 :: Test
125 test_doesnt_contain_point4 =
126 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
132 exterior_point = (0, 0, 0)
133 t = Tetrahedron { v0 = p0,
139 test_doesnt_contain_point5 :: Test
140 test_doesnt_contain_point5 =
141 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
147 exterior_point = (0, 0, 0)
148 t = Tetrahedron { v0 = p0,
154 tetrahedron_tests :: [Test]
155 tetrahedron_tests = [test_volume1,
157 test_contains_point1,
158 test_doesnt_contain_point1,
159 test_doesnt_contain_point2,
160 test_doesnt_contain_point3,
161 test_doesnt_contain_point4,
162 test_doesnt_contain_point5 ]
164 prop_b0_v0_always_unity :: Tetrahedron -> Property
165 prop_b0_v0_always_unity t =
166 (volume t) > 0 ==> (b0 t) (v0 t) ~= 1.0
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 prop_b0_v2_always_zero :: Tetrahedron -> Property
173 prop_b0_v2_always_zero t =
174 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
176 prop_b0_v3_always_zero :: Tetrahedron -> Property
177 prop_b0_v3_always_zero t =
178 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
180 prop_b1_v1_always_unity :: Tetrahedron -> Property
181 prop_b1_v1_always_unity t =
182 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
184 prop_b1_v0_always_zero :: Tetrahedron -> Property
185 prop_b1_v0_always_zero t =
186 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
188 prop_b1_v2_always_zero :: Tetrahedron -> Property
189 prop_b1_v2_always_zero t =
190 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
192 prop_b1_v3_always_zero :: Tetrahedron -> Property
193 prop_b1_v3_always_zero t =
194 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
196 prop_b2_v2_always_unity :: Tetrahedron -> Property
197 prop_b2_v2_always_unity t =
198 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
200 prop_b2_v0_always_zero :: Tetrahedron -> Property
201 prop_b2_v0_always_zero t =
202 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
204 prop_b2_v1_always_zero :: Tetrahedron -> Property
205 prop_b2_v1_always_zero t =
206 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
208 prop_b2_v3_always_zero :: Tetrahedron -> Property
209 prop_b2_v3_always_zero t =
210 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
212 prop_b3_v3_always_unity :: Tetrahedron -> Property
213 prop_b3_v3_always_unity t =
214 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
216 prop_b3_v0_always_zero :: Tetrahedron -> Property
217 prop_b3_v0_always_zero t =
218 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
220 prop_b3_v1_always_zero :: Tetrahedron -> Property
221 prop_b3_v1_always_zero t =
222 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
224 prop_b3_v2_always_zero :: Tetrahedron -> Property
225 prop_b3_v2_always_zero t =
226 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
229 -- Used for convenience in the next few tests.
230 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
231 p t i j k l = (polynomial t) (xi t i j k l)
233 -- | Given in Sorokina and Zeilfelder, p. 78.
234 prop_c3000_identity :: Tetrahedron -> Property
235 prop_c3000_identity t =
237 c t 3 0 0 0 ~= p t 3 0 0 0
239 -- | Given in Sorokina and Zeilfelder, p. 78.
240 prop_c2100_identity :: Tetrahedron -> Property
241 prop_c2100_identity t =
243 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
245 term1 = (1/3)*(p t 0 3 0 0)
246 term2 = (5/6)*(p t 3 0 0 0)
247 term3 = 3*(p t 2 1 0 0)
248 term4 = (3/2)*(p t 1 2 0 0)
250 -- | Given in Sorokina and Zeilfelder, p. 78.
251 prop_c1110_identity :: Tetrahedron -> Property
252 prop_c1110_identity t =
254 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
256 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
257 term2 = (9/2)*(p t 1 1 1 0)
258 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
259 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))