4 import Control.Monad (unless)
9 import Cube (Cube(grid), cube_at, top)
18 import Grid (Grid(h), make_grid)
24 -- | An HUnit assertion that wraps the almost_equals function. Stolen
25 -- from the definition of assertEqual in Test/HUnit/Base.hs.
26 assertAlmostEqual :: String -> Double -> Double -> Assertion
27 assertAlmostEqual preface expected actual =
28 unless (actual ~= expected) (assertFailure msg)
29 where msg = (if null preface then "" else preface ++ "\n") ++
30 "expected: " ++ show expected ++ "\n but got: " ++ show actual
33 -- | Values of the function f(x,y,z) = 1 + x + xy + xyz taken at nine
34 -- points (hi, hj, jk) with h = 1. From example one in the paper.
35 -- Used in the next bunch of tests.
36 trilinear :: [[[Double]]]
37 trilinear = [ [ [ 1, 2, 3 ],
47 -- | Check the value of c0030 for any tetrahedron belonging to the
48 -- cube centered on (1,1,1) with a grid constructed from the
49 -- trilinear values. See example one in the paper.
50 test_trilinear_c0030 :: Test
51 test_trilinear_c0030 =
52 TestCase $ assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
54 g = make_grid 1 trilinear
55 cube = cube_at g 1 1 1
56 t = head (tetrahedrons cube) -- Any one will do.
59 -- | Check the value of c0003 for any tetrahedron belonging to the
60 -- cube centered on (1,1,1) with a grid constructed from the
61 -- trilinear values. See example one in the paper.
62 test_trilinear_c0003 :: Test
63 test_trilinear_c0003 =
64 TestCase $ assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
66 g = make_grid 1 trilinear
67 cube = cube_at g 1 1 1
68 t = head (tetrahedrons cube) -- Any one will do.
71 -- | Check the value of c0021 for any tetrahedron belonging to the
72 -- cube centered on (1,1,1) with a grid constructed from the
73 -- trilinear values. See example one in the paper.
74 test_trilinear_c0021 :: Test
75 test_trilinear_c0021 =
76 TestCase $ assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
78 g = make_grid 1 trilinear
79 cube = cube_at g 1 1 1
80 t = head (tetrahedrons cube) -- Any one will do.
83 -- | Check the value of c0012 for any tetrahedron belonging to the
84 -- cube centered on (1,1,1) with a grid constructed from the
85 -- trilinear values. See example one in the paper.
86 test_trilinear_c0012 :: Test
87 test_trilinear_c0012 =
88 TestCase $ assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
90 g = make_grid 1 trilinear
91 cube = cube_at g 1 1 1
92 t = head (tetrahedrons cube) -- Any one will do.
95 -- | Check the value of c0120 for any tetrahedron belonging to the
96 -- cube centered on (1,1,1) with a grid constructed from the
97 -- trilinear values. See example one in the paper.
98 test_trilinear_c0120 :: Test
99 test_trilinear_c0120 =
100 TestCase $ assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
102 g = make_grid 1 trilinear
103 cube = cube_at g 1 1 1
104 t = head (tetrahedrons cube) -- Any one will do.
107 -- | Check the value of c0102 for any tetrahedron belonging to the
108 -- cube centered on (1,1,1) with a grid constructed from the
109 -- trilinear values. See example one in the paper.
110 test_trilinear_c0102 :: Test
111 test_trilinear_c0102 =
112 TestCase $ assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
114 g = make_grid 1 trilinear
115 cube = cube_at g 1 1 1
116 t = head (tetrahedrons cube) -- Any one will do.
119 -- | Check the value of c0111 for any tetrahedron belonging to the
120 -- cube centered on (1,1,1) with a grid constructed from the
121 -- trilinear values. See example one in the paper.
122 test_trilinear_c0111 :: Test
123 test_trilinear_c0111 =
124 TestCase $ assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
126 g = make_grid 1 trilinear
127 cube = cube_at g 1 1 1
128 t = head (tetrahedrons cube) -- Any one will do.
131 -- | Check the value of c0210 for any tetrahedron belonging to the
132 -- cube centered on (1,1,1) with a grid constructed from the
133 -- trilinear values. See example one in the paper.
134 test_trilinear_c0210 :: Test
135 test_trilinear_c0210 =
136 TestCase $ assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
138 g = make_grid 1 trilinear
139 cube = cube_at g 1 1 1
140 t = head (tetrahedrons cube) -- Any one will do.
143 -- | Check the value of c0201 for any tetrahedron belonging to the
144 -- cube centered on (1,1,1) with a grid constructed from the
145 -- trilinear values. See example one in the paper.
146 test_trilinear_c0201 :: Test
147 test_trilinear_c0201 =
148 TestCase $ assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
150 g = make_grid 1 trilinear
151 cube = cube_at g 1 1 1
152 t = head (tetrahedrons cube) -- Any one will do.
155 -- | Check the value of c0300 for any tetrahedron belonging to the
156 -- cube centered on (1,1,1) with a grid constructed from the
157 -- trilinear values. See example one in the paper.
158 test_trilinear_c0300 :: Test
159 test_trilinear_c0300 =
160 TestCase $ assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
162 g = make_grid 1 trilinear
163 cube = cube_at g 1 1 1
164 t = head (tetrahedrons cube) -- Any one will do.
167 -- | Check the value of c1020 for any tetrahedron belonging to the
168 -- cube centered on (1,1,1) with a grid constructed from the
169 -- trilinear values. See example one in the paper.
170 test_trilinear_c1020 :: Test
171 test_trilinear_c1020 =
172 TestCase $ assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
174 g = make_grid 1 trilinear
175 cube = cube_at g 1 1 1
176 t = head (tetrahedrons cube) -- Any one will do.
180 face_tests = [test_trilinear_c0030,
181 test_trilinear_c0003,
182 test_trilinear_c0021,
183 test_trilinear_c0012,
184 test_trilinear_c0120,
185 test_trilinear_c0102,
186 test_trilinear_c0111,
187 test_trilinear_c0210,
188 test_trilinear_c0201,
189 test_trilinear_c0300,
190 test_trilinear_c1020]
195 -- | Since the grid size is necessarily positive, all tetrahedrons
196 -- (which comprise cubes of positive volume) must have positive volume
198 prop_all_volumes_positive :: Cube -> Property
199 prop_all_volumes_positive c =
200 (delta > 0) ==> (null nonpositive_volumes)
204 volumes = map volume ts
205 nonpositive_volumes = filter (<= 0) volumes
208 -- | Given in Sorokina and Zeilfelder, p. 78.
209 prop_cijk1_identity :: Cube -> Bool
210 prop_cijk1_identity cube =
211 and [ c t0' i j k 1 ~= (c t1' (i+1) j k 0) * ((b0 t0') (v3 t1')) +
212 (c t1' i (j+1) k 0) * ((b1 t0') (v3 t1')) +
213 (c t1' i j (k+1) 0) * ((b2 t0') (v3 t1')) +
214 (c t1' i j k 1) * ((b3 t0') (v3 t1')) | i <- [0..2],
219 t0 = tetrahedron0 (face0 cube)
220 t1 = tetrahedron1 (face0 cube)
221 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
222 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
224 -- | Given in Sorokina and Zeilfelder, p. 79.
225 prop_c0120_identity1 :: Cube -> Bool
226 prop_c0120_identity1 cube =
227 c t0' 0 1 2 0 ~= (c t0' 0 0 2 1 + c t1' 0 0 2 1) / 2
229 t0 = tetrahedron0 (face0 cube)
230 t1 = tetrahedron1 (face0 cube)
231 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
232 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
235 -- | Given in Sorokina and Zeilfelder, p. 79.
236 prop_c0210_identity1 :: Cube -> Bool
237 prop_c0210_identity1 cube =
238 c t0' 0 2 1 0 ~= (c t0' 0 1 1 1 + c t1' 0 1 1 1) / 2
240 t0 = tetrahedron0 (face0 cube)
241 t1 = tetrahedron1 (face0 cube)
242 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
243 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
246 -- | Given in Sorokina and Zeilfelder, p. 79.
247 prop_c0300_identity1 :: Cube -> Bool
248 prop_c0300_identity1 cube =
249 c t0' 0 3 0 0 ~= (c t0' 0 2 0 1 + c t1' 0 2 0 1) / 2
251 t0 = tetrahedron0 (face0 cube)
252 t1 = tetrahedron1 (face0 cube)
253 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
254 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
256 -- | Given in Sorokina and Zeilfelder, p. 79.
257 prop_c1110_identity :: Cube -> Bool
258 prop_c1110_identity cube =
259 c t0' 1 1 1 0 ~= (c t0' 1 0 1 1 + c t1' 1 0 1 1) / 2
261 t0 = tetrahedron0 (face0 cube)
262 t1 = tetrahedron1 (face0 cube)
263 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
264 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
267 -- | Given in Sorokina and Zeilfelder, p. 79.
268 prop_c1200_identity1 :: Cube -> Bool
269 prop_c1200_identity1 cube =
270 c t0' 1 2 0 0 ~= (c t0' 1 1 0 1 + c t1' 1 1 0 1) / 2
272 t0 = tetrahedron0 (face0 cube)
273 t1 = tetrahedron1 (face0 cube)
274 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
275 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
278 -- | Given in Sorokina and Zeilfelder, p. 79.
279 prop_c2100_identity1 :: Cube -> Bool
280 prop_c2100_identity1 cube =
281 c t0' 2 1 0 0 ~= (c t0' 2 0 0 1 + c t1' 2 0 0 1) / 2
283 t0 = tetrahedron0 (face0 cube)
284 t1 = tetrahedron1 (face0 cube)
285 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
286 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
289 -- | Given in Sorokina and Zeilfelder, p. 79.
290 prop_c0102_identity1 :: Cube -> Bool
291 prop_c0102_identity1 cube =
292 c t0' 0 1 0 2 ~= (c t0' 0 0 1 2 + c t3' 0 0 1 2) / 2
294 t0 = tetrahedron0 (face0 cube)
295 t3 = tetrahedron3 (face0 cube)
296 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
297 t3' = Tetrahedron cube (v3 t3) (v2 t3) (v1 t3) (v0 t3)
300 -- | Given in Sorokina and Zeilfelder, p. 79.
301 prop_c0201_identity1 :: Cube -> Bool
302 prop_c0201_identity1 cube =
303 c t0' 0 2 0 1 ~= (c t0' 0 1 1 1 + c t3' 0 1 1 1) / 2
305 t0 = tetrahedron0 (face0 cube)
306 t3 = tetrahedron3 (face0 cube)
307 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
308 t3' = Tetrahedron cube (v3 t3) (v2 t3) (v1 t3) (v0 t3)
311 -- | Given in Sorokina and Zeilfelder, p. 79.
312 prop_c0300_identity2 :: Cube -> Bool
313 prop_c0300_identity2 cube =
314 c t0' 3 0 0 0 ~= (c t0' 0 2 1 0 + c t3' 0 2 1 0) / 2
316 t0 = tetrahedron0 (face0 cube)
317 t3 = tetrahedron3 (face0 cube)
318 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
319 t3' = Tetrahedron cube (v3 t3) (v2 t3) (v1 t3) (v0 t3)
321 -- | Given in Sorokina and Zeilfelder, p. 79.
322 prop_c1101_identity :: Cube -> Bool
323 prop_c1101_identity cube =
324 c t0' 1 1 0 1 ~= (c t0' 1 1 0 1 + c t3' 1 1 0 1) / 2
326 t0 = tetrahedron0 (face0 cube)
327 t3 = tetrahedron3 (face0 cube)
328 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
329 t3' = Tetrahedron cube (v3 t3) (v2 t3) (v1 t3) (v0 t3)
332 -- | Given in Sorokina and Zeilfelder, p. 79.
333 prop_c1200_identity2 :: Cube -> Bool
334 prop_c1200_identity2 cube =
335 c t0' 1 1 1 0 ~= (c t0' 1 1 1 0 + c t3' 1 1 1 0) / 2
337 t0 = tetrahedron0 (face0 cube)
338 t3 = tetrahedron3 (face0 cube)
339 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
340 t3' = Tetrahedron cube (v3 t3) (v2 t3) (v1 t3) (v0 t3)
343 -- | Given in Sorokina and Zeilfelder, p. 79.
344 prop_c2100_identity2 :: Cube -> Bool
345 prop_c2100_identity2 cube =
346 c t0' 2 1 0 0 ~= (c t0' 2 0 1 0 + c t3' 2 0 1 0) / 2
348 t0 = tetrahedron0 (face0 cube)
349 t3 = tetrahedron3 (face0 cube)
350 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
351 t3' = Tetrahedron cube (v3 t3) (v2 t3) (v1 t3) (v0 t3)
354 -- | Given in Sorokina and Zeilfelder, p. 79.
355 prop_c3000_identity :: Cube -> Bool
356 prop_c3000_identity cube =
357 c t0' 3 0 0 0 ~= c t0' 2 1 0 0 + c t2' 2 1 0 0 - ((c t0' 2 0 1 0 + c t0' 2 0 0 1)/ 2)
359 t0 = tetrahedron0 (face0 cube)
360 t2 = tetrahedron2 (face5 cube)
361 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
362 t2' = Tetrahedron cube (v3 t2) (v2 t2) (v1 t2) (v0 t2)
365 -- | Given in Sorokina and Zeilfelder, p. 79.
366 prop_c2010_identity :: Cube -> Bool
367 prop_c2010_identity cube =
368 c t0' 2 0 1 0 ~= c t0' 1 1 1 0 + c t2' 1 1 1 0 - ((c t0' 1 0 2 0 + c t0' 1 0 1 1)/ 2)
370 t0 = tetrahedron0 (face0 cube)
371 t2 = tetrahedron2 (face5 cube)
372 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
373 t2' = Tetrahedron cube (v3 t2) (v2 t2) (v1 t2) (v0 t2)
376 -- | Given in Sorokina and Zeilfelder, p. 79.
377 prop_c2001_identity :: Cube -> Bool
378 prop_c2001_identity cube =
379 c t0' 2 0 0 1 ~= c t0' 1 1 0 1 + c t2' 1 1 0 1 - ((c t0' 1 0 0 2 + c t0' 1 0 1 1)/ 2)
381 t0 = tetrahedron0 (face0 cube)
382 t2 = tetrahedron2 (face5 cube)
383 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
384 t2' = Tetrahedron cube (v3 t2) (v2 t2) (v1 t2) (v0 t2)
386 -- | Given in Sorokina and Zeilfelder, p. 79.
387 prop_c1020_identity :: Cube -> Bool
388 prop_c1020_identity cube =
389 c t0' 1 0 2 0 ~= c t0' 0 1 2 0 + c t2' 0 1 2 0 - ((c t0' 0 0 3 0 + c t0' 0 0 2 1)/ 2)
391 t0 = tetrahedron0 (face0 cube)
392 t2 = tetrahedron2 (face5 cube)
393 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
394 t2' = Tetrahedron cube (v3 t2) (v2 t2) (v1 t2) (v0 t2)
397 -- | Given in Sorokina and Zeilfelder, p. 79.
398 prop_c1002_identity :: Cube -> Bool
399 prop_c1002_identity cube =
400 c t0' 1 0 0 2 ~= c t0' 0 1 0 2 + c t2' 0 1 0 2 - ((c t0' 0 0 0 3 + c t0' 0 0 1 2)/ 2)
402 t0 = tetrahedron0 (face0 cube)
403 t2 = tetrahedron2 (face5 cube)
404 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
405 t2' = Tetrahedron cube (v3 t2) (v2 t2) (v1 t2) (v0 t2)
408 -- | Given in Sorokina and Zeilfelder, p. 79.
409 prop_c1011_identity :: Cube -> Bool
410 prop_c1011_identity cube =
411 c t0' 1 0 1 1 ~= c t0' 0 1 1 1 + c t2' 0 1 1 1 - ((c t0' 0 0 1 2 + c t0' 0 0 2 1)/ 2)
413 t0 = tetrahedron0 (face0 cube)
414 t2 = tetrahedron2 (face5 cube)
415 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
416 t2' = Tetrahedron cube (v3 t2) (v2 t2) (v1 t2) (v0 t2)
419 -- | Given in Sorokina and Zeilfelder, p. 80.
420 prop_c0120_identity2 :: Cube -> Bool
421 prop_c0120_identity2 cube =
422 c t0' 0 1 2 0 ~= (c t0' 1 0 2 0 + c t1' 1 0 2 0) / 2
424 t0 = tetrahedron0 (face0 cube)
425 t1 = tetrahedron0 (face2 (top cube))
426 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
427 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
430 -- | Given in Sorokina and Zeilfelder, p. 80.
431 prop_c0102_identity2 :: Cube -> Bool
432 prop_c0102_identity2 cube =
433 c t0' 0 1 0 2 ~= (c t0' 1 0 0 2 + c t1' 1 0 0 2) / 2
435 t0 = tetrahedron0 (face0 cube)
436 t1 = tetrahedron0 (face2 (top cube))
437 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
438 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
441 -- | Given in Sorokina and Zeilfelder, p. 80.
442 prop_c0111_identity :: Cube -> Bool
443 prop_c0111_identity cube =
444 c t0' 0 1 1 1 ~= (c t0' 1 0 1 1 + c t1' 1 0 1 1) / 2
446 t0 = tetrahedron0 (face0 cube)
447 t1 = tetrahedron0 (face2 (top cube))
448 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
449 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
452 -- | Given in Sorokina and Zeilfelder, p. 80.
453 prop_c0210_identity2 :: Cube -> Bool
454 prop_c0210_identity2 cube =
455 c t0 0 2 1 0 ~= (c t0 1 1 1 0 + c t1 1 1 1 0) / 2
457 t0 = tetrahedron0 (face0 cube)
458 t1 = tetrahedron0 (face2 (top cube))
459 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
460 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
463 -- | Given in Sorokina and Zeilfelder, p. 80.
464 prop_c0201_identity2 :: Cube -> Bool
465 prop_c0201_identity2 cube =
466 c t0 0 2 0 1 ~= (c t0 1 1 0 1 + c t1 1 1 0 1) / 2
468 t0 = tetrahedron0 (face0 cube)
469 t1 = tetrahedron0 (face2 (top cube))
470 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
471 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)
474 -- | Given in Sorokina and Zeilfelder, p. 80.
475 prop_c0300_identity3 :: Cube -> Bool
476 prop_c0300_identity3 cube =
477 c t0 0 3 0 0 ~= (c t0 1 2 0 0 + c t1 1 2 0 0) / 2
479 t0 = tetrahedron0 (face0 cube)
480 t1 = tetrahedron0 (face2 (top cube))
481 t0' = Tetrahedron cube (v3 t0) (v2 t0) (v1 t0) (v0 t0)
482 t1' = Tetrahedron cube (v3 t1) (v2 t1) (v0 t1) (v1 t1)