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)
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 { v0 = p0,
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 { v0 = p0,
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 { v0 = p0,
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)
85 t = Tetrahedron { v0 = p0,
92 test_doesnt_contain_point2 :: Test
93 test_doesnt_contain_point2 =
94 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
100 exterior_point = (0, 0, 0)
101 t = Tetrahedron { v0 = p0,
107 test_doesnt_contain_point3 :: Test
108 test_doesnt_contain_point3 =
109 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
115 exterior_point = (0, 0, 0)
116 t = Tetrahedron { v0 = p0,
122 test_doesnt_contain_point4 :: Test
123 test_doesnt_contain_point4 =
124 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
130 exterior_point = (0, 0, 0)
131 t = Tetrahedron { v0 = p0,
137 test_doesnt_contain_point5 :: Test
138 test_doesnt_contain_point5 =
139 TestCase $ assertEqual "doesn't contain an exterior point" False (contains_point t exterior_point)
145 exterior_point = (0, 0, 0)
146 t = Tetrahedron { v0 = p0,
152 tetrahedron_tests :: [Test]
153 tetrahedron_tests = [test_volume1,
155 test_contains_point1,
156 test_doesnt_contain_point1,
157 test_doesnt_contain_point2,
158 test_doesnt_contain_point3,
159 test_doesnt_contain_point4,
160 test_doesnt_contain_point5 ]
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 prop_b0_v1_always_zero :: Tetrahedron -> Property
167 prop_b0_v1_always_zero t =
168 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
170 prop_b0_v2_always_zero :: Tetrahedron -> Property
171 prop_b0_v2_always_zero t =
172 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
174 prop_b0_v3_always_zero :: Tetrahedron -> Property
175 prop_b0_v3_always_zero t =
176 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
178 prop_b1_v1_always_unity :: Tetrahedron -> Property
179 prop_b1_v1_always_unity t =
180 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
182 prop_b1_v0_always_zero :: Tetrahedron -> Property
183 prop_b1_v0_always_zero t =
184 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
186 prop_b1_v2_always_zero :: Tetrahedron -> Property
187 prop_b1_v2_always_zero t =
188 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
190 prop_b1_v3_always_zero :: Tetrahedron -> Property
191 prop_b1_v3_always_zero t =
192 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
194 prop_b2_v2_always_unity :: Tetrahedron -> Property
195 prop_b2_v2_always_unity t =
196 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
198 prop_b2_v0_always_zero :: Tetrahedron -> Property
199 prop_b2_v0_always_zero t =
200 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
202 prop_b2_v1_always_zero :: Tetrahedron -> Property
203 prop_b2_v1_always_zero t =
204 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
206 prop_b2_v3_always_zero :: Tetrahedron -> Property
207 prop_b2_v3_always_zero t =
208 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
210 prop_b3_v3_always_unity :: Tetrahedron -> Property
211 prop_b3_v3_always_unity t =
212 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
214 prop_b3_v0_always_zero :: Tetrahedron -> Property
215 prop_b3_v0_always_zero t =
216 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
218 prop_b3_v1_always_zero :: Tetrahedron -> Property
219 prop_b3_v1_always_zero t =
220 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
222 prop_b3_v2_always_zero :: Tetrahedron -> Property
223 prop_b3_v2_always_zero t =
224 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
227 -- Used for convenience in the next few tests.
228 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
229 p t i j k l = (polynomial t) (xi t i j k l)
231 -- | Given in Sorokina and Zeilfelder, p. 78.
232 prop_c3000_identity :: Tetrahedron -> Property
233 prop_c3000_identity t =
235 c t 3 0 0 0 ~= p t 3 0 0 0
237 -- | Given in Sorokina and Zeilfelder, p. 78.
238 prop_c2100_identity :: Tetrahedron -> Property
239 prop_c2100_identity t =
241 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
243 term1 = (1/3)*(p t 0 3 0 0)
244 term2 = (5/6)*(p t 3 0 0 0)
245 term3 = 3*(p t 2 1 0 0)
246 term4 = (3/2)*(p t 1 2 0 0)
248 -- | Given in Sorokina and Zeilfelder, p. 78.
249 prop_c1110_identity :: Tetrahedron -> Property
250 prop_c1110_identity t =
252 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
254 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
255 term2 = (9/2)*(p t 1 1 1 0)
256 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
257 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))