]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Tetrahedron.hs
Remove the Tetrahedron 'number' field from tests.
[spline3.git] / src / Tests / Tetrahedron.hs
1 module Tests.Tetrahedron
2 where
3
4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
6 import Test.HUnit
7 import Test.QuickCheck (Property, (==>))
8
9 import Cardinal
10 import Comparisons
11 import FunctionValues
12 import Tetrahedron
13 import ThreeDimensional
14
15 -- HUnit Tests
16
17
18 -- | Check the volume of a particular tetrahedron (computed by hand)
19 -- and whether or not it contains a specific point chosen to be
20 -- outside of it. Its vertices are in clockwise order, so the volume
21 -- should be negative.
22 tetrahedron1_geometry_tests :: Test.Framework.Test
23 tetrahedron1_geometry_tests =
24 testGroup "tetrahedron1 geometry"
25 [ testCase "volume1" volume1,
26 testCase "doesn't contain point1" doesnt_contain_point1]
27 where
28 p0 = (0, -0.5, 0)
29 p1 = (0, 0.5, 0)
30 p2 = (2, 0, 0)
31 p3 = (1, 0, 1)
32 t = Tetrahedron { v0 = p0,
33 v1 = p1,
34 v2 = p2,
35 v3 = p3,
36 fv = empty_values,
37 precomputed_volume = 0 }
38
39 volume1 :: Assertion
40 volume1 =
41 assertEqual "volume is correct" True (vol ~= (-1/3))
42 where
43 vol = volume t
44
45 doesnt_contain_point1 :: Assertion
46 doesnt_contain_point1 =
47 assertEqual "doesn't contain an exterior point" False contained
48 where
49 exterior_point = (5, 2, -9.0212)
50 contained = contains_point t exterior_point
51
52
53 -- | Check the volume of a particular tetrahedron (computed by hand)
54 -- and whether or not it contains a specific point chosen to be
55 -- inside of it. Its vertices are in counter-clockwise order, so the
56 -- volume should be positive.
57 tetrahedron2_geometry_tests :: Test.Framework.Test
58 tetrahedron2_geometry_tests =
59 testGroup "tetrahedron2 geometry"
60 [ testCase "volume1" volume1,
61 testCase "contains point1" contains_point1]
62 where
63 p0 = (0, -0.5, 0)
64 p1 = (2, 0, 0)
65 p2 = (0, 0.5, 0)
66 p3 = (1, 0, 1)
67 t = Tetrahedron { v0 = p0,
68 v1 = p1,
69 v2 = p2,
70 v3 = p3,
71 fv = empty_values,
72 precomputed_volume = 0 }
73
74 volume1 :: Assertion
75 volume1 = assertEqual "volume1 is correct" True (vol ~= (1/3))
76 where
77 vol = volume t
78
79 contains_point1 :: Assertion
80 contains_point1 = assertEqual "contains an inner point" True contained
81 where
82 inner_point = (1, 0, 0.5)
83 contained = contains_point t inner_point
84
85
86 -- | Ensure that tetrahedra do not contain a particular point chosen to
87 -- be outside of them.
88 containment_tests :: Test.Framework.Test
89 containment_tests =
90 testGroup "containment tests"
91 [ testCase "doesn't contain point2" doesnt_contain_point2,
92 testCase "doesn't contain point3" doesnt_contain_point3,
93 testCase "doesn't contain point4" doesnt_contain_point4,
94 testCase "doesn't contain point5" doesnt_contain_point5]
95 where
96 p2 = (0.5, 0.5, 1)
97 p3 = (0.5, 0.5, 0.5)
98 exterior_point = (0, 0, 0)
99
100 doesnt_contain_point2 :: Assertion
101 doesnt_contain_point2 =
102 assertEqual "doesn't contain an exterior point" False contained
103 where
104 p0 = (0, 1, 1)
105 p1 = (1, 1, 1)
106 t = Tetrahedron { v0 = p0,
107 v1 = p1,
108 v2 = p2,
109 v3 = p3,
110 fv = empty_values,
111 precomputed_volume = 0 }
112 contained = contains_point t exterior_point
113
114
115 doesnt_contain_point3 :: Assertion
116 doesnt_contain_point3 =
117 assertEqual "doesn't contain an exterior point" False contained
118 where
119 p0 = (1, 1, 1)
120 p1 = (1, 0, 1)
121 t = Tetrahedron { v0 = p0,
122 v1 = p1,
123 v2 = p2,
124 v3 = p3,
125 fv = empty_values,
126 precomputed_volume = 0 }
127 contained = contains_point t exterior_point
128
129
130 doesnt_contain_point4 :: Assertion
131 doesnt_contain_point4 =
132 assertEqual "doesn't contain an exterior point" False contained
133 where
134 p0 = (1, 0, 1)
135 p1 = (0, 0, 1)
136 t = Tetrahedron { v0 = p0,
137 v1 = p1,
138 v2 = p2,
139 v3 = p3,
140 fv = empty_values,
141 precomputed_volume = 0 }
142 contained = contains_point t exterior_point
143
144
145 doesnt_contain_point5 :: Assertion
146 doesnt_contain_point5 =
147 assertEqual "doesn't contain an exterior point" False contained
148 where
149 p0 = (0, 0, 1)
150 p1 = (0, 1, 1)
151 t = Tetrahedron { v0 = p0,
152 v1 = p1,
153 v2 = p2,
154 v3 = p3,
155 fv = empty_values,
156 precomputed_volume = 0 }
157 contained = contains_point t exterior_point
158
159
160 -- | The barycentric coordinate of v0 with respect to itself should
161 -- be one.
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
165
166 -- | The barycentric coordinate of v1 with respect to v0 should
167 -- be zero.
168 prop_b0_v1_always_zero :: Tetrahedron -> Property
169 prop_b0_v1_always_zero t =
170 (volume t) > 0 ==> (b0 t) (v1 t) ~= 0
171
172 -- | The barycentric coordinate of v2 with respect to v0 should
173 -- be zero.
174 prop_b0_v2_always_zero :: Tetrahedron -> Property
175 prop_b0_v2_always_zero t =
176 (volume t) > 0 ==> (b0 t) (v2 t) ~= 0
177
178 -- | The barycentric coordinate of v3 with respect to v0 should
179 -- be zero.
180 prop_b0_v3_always_zero :: Tetrahedron -> Property
181 prop_b0_v3_always_zero t =
182 (volume t) > 0 ==> (b0 t) (v3 t) ~= 0
183
184 -- | The barycentric coordinate of v1 with respect to itself should
185 -- be one.
186 prop_b1_v1_always_unity :: Tetrahedron -> Property
187 prop_b1_v1_always_unity t =
188 (volume t) > 0 ==> (b1 t) (v1 t) ~= 1.0
189
190 -- | The barycentric coordinate of v0 with respect to v1 should
191 -- be zero.
192 prop_b1_v0_always_zero :: Tetrahedron -> Property
193 prop_b1_v0_always_zero t =
194 (volume t) > 0 ==> (b1 t) (v0 t) ~= 0
195
196 -- | The barycentric coordinate of v2 with respect to v1 should
197 -- be zero.
198 prop_b1_v2_always_zero :: Tetrahedron -> Property
199 prop_b1_v2_always_zero t =
200 (volume t) > 0 ==> (b1 t) (v2 t) ~= 0
201
202 -- | The barycentric coordinate of v3 with respect to v1 should
203 -- be zero.
204 prop_b1_v3_always_zero :: Tetrahedron -> Property
205 prop_b1_v3_always_zero t =
206 (volume t) > 0 ==> (b1 t) (v3 t) ~= 0
207
208 -- | The barycentric coordinate of v2 with respect to itself should
209 -- be one.
210 prop_b2_v2_always_unity :: Tetrahedron -> Property
211 prop_b2_v2_always_unity t =
212 (volume t) > 0 ==> (b2 t) (v2 t) ~= 1.0
213
214 -- | The barycentric coordinate of v0 with respect to v2 should
215 -- be zero.
216 prop_b2_v0_always_zero :: Tetrahedron -> Property
217 prop_b2_v0_always_zero t =
218 (volume t) > 0 ==> (b2 t) (v0 t) ~= 0
219
220 -- | The barycentric coordinate of v1 with respect to v2 should
221 -- be zero.
222 prop_b2_v1_always_zero :: Tetrahedron -> Property
223 prop_b2_v1_always_zero t =
224 (volume t) > 0 ==> (b2 t) (v1 t) ~= 0
225
226 -- | The barycentric coordinate of v3 with respect to v2 should
227 -- be zero.
228 prop_b2_v3_always_zero :: Tetrahedron -> Property
229 prop_b2_v3_always_zero t =
230 (volume t) > 0 ==> (b2 t) (v3 t) ~= 0
231
232 -- | The barycentric coordinate of v3 with respect to itself should
233 -- be one.
234 prop_b3_v3_always_unity :: Tetrahedron -> Property
235 prop_b3_v3_always_unity t =
236 (volume t) > 0 ==> (b3 t) (v3 t) ~= 1.0
237
238 -- | The barycentric coordinate of v0 with respect to v3 should
239 -- be zero.
240 prop_b3_v0_always_zero :: Tetrahedron -> Property
241 prop_b3_v0_always_zero t =
242 (volume t) > 0 ==> (b3 t) (v0 t) ~= 0
243
244 -- | The barycentric coordinate of v1 with respect to v3 should
245 -- be zero.
246 prop_b3_v1_always_zero :: Tetrahedron -> Property
247 prop_b3_v1_always_zero t =
248 (volume t) > 0 ==> (b3 t) (v1 t) ~= 0
249
250 -- | The barycentric coordinate of v2 with respect to v3 should
251 -- be zero.
252 prop_b3_v2_always_zero :: Tetrahedron -> Property
253 prop_b3_v2_always_zero t =
254 (volume t) > 0 ==> (b3 t) (v2 t) ~= 0
255
256
257 -- | Used for convenience in the next few tests; not a test itself.
258 p :: Tetrahedron -> Int -> Int -> Int -> Int -> Double
259 p t i j k l = (polynomial t) (xi t i j k l)
260
261 -- | Given in Sorokina and Zeilfelder, p. 78.
262 prop_c3000_identity :: Tetrahedron -> Property
263 prop_c3000_identity t =
264 (volume t) > 0 ==>
265 c t 3 0 0 0 ~= p t 3 0 0 0
266
267 -- | Given in Sorokina and Zeilfelder, p. 78.
268 prop_c2100_identity :: Tetrahedron -> Property
269 prop_c2100_identity t =
270 (volume t) > 0 ==>
271 c t 2 1 0 0 ~= (term1 - term2 + term3 - term4)
272 where
273 term1 = (1/3)*(p t 0 3 0 0)
274 term2 = (5/6)*(p t 3 0 0 0)
275 term3 = 3*(p t 2 1 0 0)
276 term4 = (3/2)*(p t 1 2 0 0)
277
278 -- | Given in Sorokina and Zeilfelder, p. 78.
279 prop_c1110_identity :: Tetrahedron -> Property
280 prop_c1110_identity t =
281 (volume t) > 0 ==>
282 c t 1 1 1 0 ~= (term1 + term2 - term3 - term4)
283 where
284 term1 = (1/3)*((p t 3 0 0 0) + (p t 0 3 0 0) + (p t 0 0 3 0))
285 term2 = (9/2)*(p t 1 1 1 0)
286 term3 = (3/4)*((p t 2 1 0 0) + (p t 1 2 0 0) + (p t 2 0 1 0))
287 term4 = (3/4)*((p t 1 0 2 0) + (p t 0 2 1 0) + (p t 0 1 2 0))
288
289
290 prop_swapping_vertices_doesnt_affect_coefficients1 :: Tetrahedron -> Bool
291 prop_swapping_vertices_doesnt_affect_coefficients1 t =
292 c t 0 0 1 2 == c t' 0 0 1 2
293 where
294 t' = t { v0 = (v1 t), v1 = (v0 t) }
295
296 prop_swapping_vertices_doesnt_affect_coefficients2 :: Tetrahedron -> Bool
297 prop_swapping_vertices_doesnt_affect_coefficients2 t =
298 c t 0 1 1 1 == c t' 0 1 1 1
299 where
300 t' = t { v2 = (v3 t), v3 = (v2 t) }
301
302 prop_swapping_vertices_doesnt_affect_coefficients3 :: Tetrahedron -> Bool
303 prop_swapping_vertices_doesnt_affect_coefficients3 t =
304 c t 2 1 0 0 == c t' 2 1 0 0
305 where
306 t' = t { v2 = (v3 t), v3 = (v2 t) }
307
308 prop_swapping_vertices_doesnt_affect_coefficients4 :: Tetrahedron -> Bool
309 prop_swapping_vertices_doesnt_affect_coefficients4 t =
310 c t 2 0 0 1 == c t' 2 0 0 1
311 where
312 t' = t { v0 = (v3 t), v3 = (v0 t) }