]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cube.hs
418730ab61245b8ea028beaa3d67035b3632e77a
[spline3.git] / src / Tests / Cube.hs
1 module Tests.Cube
2 where
3
4 import Test.QuickCheck
5
6 import Comparisons
7 import Cube
8 import FunctionValues (FunctionValues)
9 import Tests.FunctionValues ()
10 import Tetrahedron (b0, b1, b2, b3, c,
11 v0, v1, v2, v3, volume)
12
13 instance Arbitrary Cube where
14 arbitrary = do
15 (Positive h') <- arbitrary :: Gen (Positive Double)
16 i' <- choose (coordmin, coordmax)
17 j' <- choose (coordmin, coordmax)
18 k' <- choose (coordmin, coordmax)
19 fv' <- arbitrary :: Gen FunctionValues
20 return (Cube h' i' j' k' fv')
21 where
22 coordmin = -268435456 -- -(2^29 / 2)
23 coordmax = 268435456 -- +(2^29 / 2)
24
25
26 -- Quickcheck tests.
27
28 -- | Since the grid size is necessarily positive, all tetrahedrons
29 -- (which comprise cubes of positive volume) must have positive volume
30 -- as well.
31 prop_all_volumes_positive :: Cube -> Bool
32 prop_all_volumes_positive cube =
33 null nonpositive_volumes
34 where
35 ts = tetrahedrons cube
36 volumes = map volume ts
37 nonpositive_volumes = filter (<= 0) volumes
38
39 -- | In fact, since all of the tetrahedra are identical, we should
40 -- already know their volumes. There's 24 tetrahedra to a cube, so
41 -- we'd expect the volume of each one to be (1/24)*h^3.
42 prop_tetrahedron0_volumes_exact :: Cube -> Bool
43 prop_tetrahedron0_volumes_exact cube =
44 volume (tetrahedron0 cube) ~= (1/24)*(delta^(3::Int))
45 where
46 delta = h cube
47
48 -- | In fact, since all of the tetrahedra are identical, we should
49 -- already know their volumes. There's 24 tetrahedra to a cube, so
50 -- we'd expect the volume of each one to be (1/24)*h^3.
51 prop_tetrahedron1_volumes_exact :: Cube -> Bool
52 prop_tetrahedron1_volumes_exact cube =
53 volume (tetrahedron1 cube) ~= (1/24)*(delta^(3::Int))
54 where
55 delta = h cube
56
57 -- | In fact, since all of the tetrahedra are identical, we should
58 -- already know their volumes. There's 24 tetrahedra to a cube, so
59 -- we'd expect the volume of each one to be (1/24)*h^3.
60 prop_tetrahedron2_volumes_exact :: Cube -> Bool
61 prop_tetrahedron2_volumes_exact cube =
62 volume (tetrahedron2 cube) ~= (1/24)*(delta^(3::Int))
63 where
64 delta = h cube
65
66 -- | In fact, since all of the tetrahedra are identical, we should
67 -- already know their volumes. There's 24 tetrahedra to a cube, so
68 -- we'd expect the volume of each one to be (1/24)*h^3.
69 prop_tetrahedron3_volumes_exact :: Cube -> Bool
70 prop_tetrahedron3_volumes_exact cube =
71 volume (tetrahedron3 cube) ~= (1/24)*(delta^(3::Int))
72 where
73 delta = h cube
74
75 -- | In fact, since all of the tetrahedra are identical, we should
76 -- already know their volumes. There's 24 tetrahedra to a cube, so
77 -- we'd expect the volume of each one to be (1/24)*h^3.
78 prop_tetrahedron4_volumes_exact :: Cube -> Bool
79 prop_tetrahedron4_volumes_exact cube =
80 volume (tetrahedron4 cube) ~= (1/24)*(delta^(3::Int))
81 where
82 delta = h cube
83
84 -- | In fact, since all of the tetrahedra are identical, we should
85 -- already know their volumes. There's 24 tetrahedra to a cube, so
86 -- we'd expect the volume of each one to be (1/24)*h^3.
87 prop_tetrahedron5_volumes_exact :: Cube -> Bool
88 prop_tetrahedron5_volumes_exact cube =
89 volume (tetrahedron5 cube) ~= (1/24)*(delta^(3::Int))
90 where
91 delta = h cube
92
93 -- | In fact, since all of the tetrahedra are identical, we should
94 -- already know their volumes. There's 24 tetrahedra to a cube, so
95 -- we'd expect the volume of each one to be (1/24)*h^3.
96 prop_tetrahedron6_volumes_exact :: Cube -> Bool
97 prop_tetrahedron6_volumes_exact cube =
98 volume (tetrahedron6 cube) ~= (1/24)*(delta^(3::Int))
99 where
100 delta = h cube
101
102 -- | In fact, since all of the tetrahedra are identical, we should
103 -- already know their volumes. There's 24 tetrahedra to a cube, so
104 -- we'd expect the volume of each one to be (1/24)*h^3.
105 prop_tetrahedron7_volumes_exact :: Cube -> Bool
106 prop_tetrahedron7_volumes_exact cube =
107 volume (tetrahedron7 cube) ~= (1/24)*(delta^(3::Int))
108 where
109 delta = h cube
110
111 -- | All tetrahedron should have their v0 located at the center of the cube.
112 prop_v0_all_equal :: Cube -> Bool
113 prop_v0_all_equal cube = (v0 t0) == (v0 t1)
114 where
115 t0 = head (tetrahedrons cube) -- Doesn't matter which two we choose.
116 t1 = head $ tail (tetrahedrons cube)
117
118
119 -- | This pretty much repeats the prop_all_volumes_positive property,
120 -- but will let me know which tetrahedrons's vertices are disoriented.
121 prop_tetrahedron0_volumes_positive :: Cube -> Bool
122 prop_tetrahedron0_volumes_positive cube =
123 volume (tetrahedron0 cube) > 0
124
125 -- | This pretty much repeats the prop_all_volumes_positive property,
126 -- but will let me know which tetrahedrons's vertices are disoriented.
127 prop_tetrahedron1_volumes_positive :: Cube -> Bool
128 prop_tetrahedron1_volumes_positive cube =
129 volume (tetrahedron1 cube) > 0
130
131 -- | This pretty much repeats the prop_all_volumes_positive property,
132 -- but will let me know which tetrahedrons's vertices are disoriented.
133 prop_tetrahedron2_volumes_positive :: Cube -> Bool
134 prop_tetrahedron2_volumes_positive cube =
135 volume (tetrahedron2 cube) > 0
136
137 -- | This pretty much repeats the prop_all_volumes_positive property,
138 -- but will let me know which tetrahedrons's vertices are disoriented.
139 prop_tetrahedron3_volumes_positive :: Cube -> Bool
140 prop_tetrahedron3_volumes_positive cube =
141 volume (tetrahedron3 cube) > 0
142
143 -- | This pretty much repeats the prop_all_volumes_positive property,
144 -- but will let me know which tetrahedrons's vertices are disoriented.
145 prop_tetrahedron4_volumes_positive :: Cube -> Bool
146 prop_tetrahedron4_volumes_positive cube =
147 volume (tetrahedron4 cube) > 0
148
149 -- | This pretty much repeats the prop_all_volumes_positive property,
150 -- but will let me know which tetrahedrons's vertices are disoriented.
151 prop_tetrahedron5_volumes_positive :: Cube -> Bool
152 prop_tetrahedron5_volumes_positive cube =
153 volume (tetrahedron5 cube) > 0
154
155 -- | This pretty much repeats the prop_all_volumes_positive property,
156 -- but will let me know which tetrahedrons's vertices are disoriented.
157 prop_tetrahedron6_volumes_positive :: Cube -> Bool
158 prop_tetrahedron6_volumes_positive cube =
159 volume (tetrahedron6 cube) > 0
160
161 -- | This pretty much repeats the prop_all_volumes_positive property,
162 -- but will let me know which tetrahedrons's vertices are disoriented.
163 prop_tetrahedron7_volumes_positive :: Cube -> Bool
164 prop_tetrahedron7_volumes_positive cube =
165 volume (tetrahedron7 cube) > 0
166
167 -- | This pretty much repeats the prop_all_volumes_positive property,
168 -- but will let me know which tetrahedrons's vertices are disoriented.
169 prop_tetrahedron8_volumes_positive :: Cube -> Bool
170 prop_tetrahedron8_volumes_positive cube =
171 volume (tetrahedron8 cube) > 0
172
173 -- | This pretty much repeats the prop_all_volumes_positive property,
174 -- but will let me know which tetrahedrons's vertices are disoriented.
175 prop_tetrahedron9_volumes_positive :: Cube -> Bool
176 prop_tetrahedron9_volumes_positive cube =
177 volume (tetrahedron9 cube) > 0
178
179 -- | This pretty much repeats the prop_all_volumes_positive property,
180 -- but will let me know which tetrahedrons's vertices are disoriented.
181 prop_tetrahedron10_volumes_positive :: Cube -> Bool
182 prop_tetrahedron10_volumes_positive cube =
183 volume (tetrahedron10 cube) > 0
184
185 -- | This pretty much repeats the prop_all_volumes_positive property,
186 -- but will let me know which tetrahedrons's vertices are disoriented.
187 prop_tetrahedron11_volumes_positive :: Cube -> Bool
188 prop_tetrahedron11_volumes_positive cube =
189 volume (tetrahedron11 cube) > 0
190
191 -- | This pretty much repeats the prop_all_volumes_positive property,
192 -- but will let me know which tetrahedrons's vertices are disoriented.
193 prop_tetrahedron12_volumes_positive :: Cube -> Bool
194 prop_tetrahedron12_volumes_positive cube =
195 volume (tetrahedron12 cube) > 0
196
197 -- | This pretty much repeats the prop_all_volumes_positive property,
198 -- but will let me know which tetrahedrons's vertices are disoriented.
199 prop_tetrahedron13_volumes_positive :: Cube -> Bool
200 prop_tetrahedron13_volumes_positive cube =
201 volume (tetrahedron13 cube) > 0
202
203 -- | This pretty much repeats the prop_all_volumes_positive property,
204 -- but will let me know which tetrahedrons's vertices are disoriented.
205 prop_tetrahedron14_volumes_positive :: Cube -> Bool
206 prop_tetrahedron14_volumes_positive cube =
207 volume (tetrahedron14 cube) > 0
208
209 -- | This pretty much repeats the prop_all_volumes_positive property,
210 -- but will let me know which tetrahedrons's vertices are disoriented.
211 prop_tetrahedron15_volumes_positive :: Cube -> Bool
212 prop_tetrahedron15_volumes_positive cube =
213 volume (tetrahedron15 cube) > 0
214
215 -- | This pretty much repeats the prop_all_volumes_positive property,
216 -- but will let me know which tetrahedrons's vertices are disoriented.
217 prop_tetrahedron16_volumes_positive :: Cube -> Bool
218 prop_tetrahedron16_volumes_positive cube =
219 volume (tetrahedron16 cube) > 0
220
221 -- | This pretty much repeats the prop_all_volumes_positive property,
222 -- but will let me know which tetrahedrons's vertices are disoriented.
223 prop_tetrahedron17_volumes_positive :: Cube -> Bool
224 prop_tetrahedron17_volumes_positive cube =
225 volume (tetrahedron17 cube) > 0
226
227 -- | This pretty much repeats the prop_all_volumes_positive property,
228 -- but will let me know which tetrahedrons's vertices are disoriented.
229 prop_tetrahedron18_volumes_positive :: Cube -> Bool
230 prop_tetrahedron18_volumes_positive cube =
231 volume (tetrahedron18 cube) > 0
232
233 -- | This pretty much repeats the prop_all_volumes_positive property,
234 -- but will let me know which tetrahedrons's vertices are disoriented.
235 prop_tetrahedron19_volumes_positive :: Cube -> Bool
236 prop_tetrahedron19_volumes_positive cube =
237 volume (tetrahedron19 cube) > 0
238
239 -- | This pretty much repeats the prop_all_volumes_positive property,
240 -- but will let me know which tetrahedrons's vertices are disoriented.
241 prop_tetrahedron20_volumes_positive :: Cube -> Bool
242 prop_tetrahedron20_volumes_positive cube =
243 volume (tetrahedron20 cube) > 0
244
245 -- | This pretty much repeats the prop_all_volumes_positive property,
246 -- but will let me know which tetrahedrons's vertices are disoriented.
247 prop_tetrahedron21_volumes_positive :: Cube -> Bool
248 prop_tetrahedron21_volumes_positive cube =
249 volume (tetrahedron21 cube) > 0
250
251 -- | This pretty much repeats the prop_all_volumes_positive property,
252 -- but will let me know which tetrahedrons's vertices are disoriented.
253 prop_tetrahedron22_volumes_positive :: Cube -> Bool
254 prop_tetrahedron22_volumes_positive cube =
255 volume (tetrahedron22 cube) > 0
256
257 -- | This pretty much repeats the prop_all_volumes_positive property,
258 -- but will let me know which tetrahedrons's vertices are disoriented.
259 prop_tetrahedron23_volumes_positive :: Cube -> Bool
260 prop_tetrahedron23_volumes_positive cube =
261 volume (tetrahedron23 cube) > 0
262
263
264 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
265 -- fourth indices of c-t3 have been switched. This is because we
266 -- store the triangles oriented such that their volume is
267 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
268 -- in opposite directions, one of them has to have negative volume!
269 prop_c0120_identity1 :: Cube -> Bool
270 prop_c0120_identity1 cube =
271 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
272 where
273 t0 = tetrahedron0 cube
274 t3 = tetrahedron3 cube
275
276
277 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
278 -- fourth indices of c-t3 have been switched. This is because we
279 -- store the triangles oriented such that their volume is
280 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
281 -- in opposite directions, one of them has to have negative volume!
282 prop_c0210_identity1 :: Cube -> Bool
283 prop_c0210_identity1 cube =
284 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
285 where
286 t0 = tetrahedron0 cube
287 t3 = tetrahedron3 cube
288
289
290 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
291 -- fourth indices of c-t3 have been switched. This is because we
292 -- store the triangles oriented such that their volume is
293 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
294 -- in opposite directions, one of them has to have negative volume!
295 prop_c0300_identity1 :: Cube -> Bool
296 prop_c0300_identity1 cube =
297 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
298 where
299 t0 = tetrahedron0 cube
300 t3 = tetrahedron3 cube
301
302
303 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
304 -- fourth indices of c-t3 have been switched. This is because we
305 -- store the triangles oriented such that their volume is
306 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
307 -- in opposite directions, one of them has to have negative volume!
308 prop_c1110_identity :: Cube -> Bool
309 prop_c1110_identity cube =
310 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
311 where
312 t0 = tetrahedron0 cube
313 t3 = tetrahedron3 cube
314
315
316 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
317 -- fourth indices of c-t3 have been switched. This is because we
318 -- store the triangles oriented such that their volume is
319 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
320 -- in opposite directions, one of them has to have negative volume!
321 prop_c1200_identity1 :: Cube -> Bool
322 prop_c1200_identity1 cube =
323 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
324 where
325 t0 = tetrahedron0 cube
326 t3 = tetrahedron3 cube
327
328
329 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
330 -- fourth indices of c-t3 have been switched. This is because we
331 -- store the triangles oriented such that their volume is
332 -- positive. If T and T-tilde share \<v0,v1,v2\> and v3,v3-tilde point
333 -- in opposite directions, one of them has to have negative volume!
334 prop_c2100_identity1 :: Cube -> Bool
335 prop_c2100_identity1 cube =
336 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
337 where
338 t0 = tetrahedron0 cube
339 t3 = tetrahedron3 cube
340
341
342
343 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
344 -- fourth indices of c-t1 have been switched. This is because we
345 -- store the triangles oriented such that their volume is
346 -- positive. If T and T-tilde share \<v0,v1,v3\> and v2,v2-tilde point
347 -- in opposite directions, one of them has to have negative volume!
348 prop_c0102_identity1 :: Cube -> Bool
349 prop_c0102_identity1 cube =
350 c t0 0 1 0 2 ~= (c t0 0 0 1 2 + c t1 0 0 2 1) / 2
351 where
352 t0 = tetrahedron0 cube
353 t1 = tetrahedron1 cube
354
355
356 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
357 -- fourth indices of c-t1 have been switched. This is because we
358 -- store the triangles oriented such that their volume is
359 -- positive. If T and T-tilde share \<v0,v1,v3\> and v2,v2-tilde point
360 -- in opposite directions, one of them has to have negative volume!
361 prop_c0201_identity1 :: Cube -> Bool
362 prop_c0201_identity1 cube =
363 c t0 0 2 0 1 ~= (c t0 0 1 1 1 + c t1 0 1 1 1) / 2
364 where
365 t0 = tetrahedron0 cube
366 t1 = tetrahedron1 cube
367
368
369 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
370 -- fourth indices of c-t1 have been switched. This is because we
371 -- store the triangles oriented such that their volume is
372 -- positive. If T and T-tilde share \<v0,v1,v3\> and v2,v2-tilde point
373 -- in opposite directions, one of them has to have negative volume!
374 prop_c0300_identity2 :: Cube -> Bool
375 prop_c0300_identity2 cube =
376 c t0 0 3 0 0 ~= (c t0 0 2 1 0 + c t1 0 2 0 1) / 2
377 where
378 t0 = tetrahedron0 cube
379 t1 = tetrahedron1 cube
380
381
382 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
383 -- fourth indices of c-t1 have been switched. This is because we
384 -- store the triangles oriented such that their volume is
385 -- positive. If T and T-tilde share \<v0,v1,v3\> and v2,v2-tilde point
386 -- in opposite directions, one of them has to have negative volume!
387 prop_c1101_identity :: Cube -> Bool
388 prop_c1101_identity cube =
389 c t0 1 1 0 1 ~= (c t0 1 0 1 1 + c t1 1 0 1 1) / 2
390 where
391 t0 = tetrahedron0 cube
392 t1 = tetrahedron1 cube
393
394
395 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
396 -- fourth indices of c-t1 have been switched. This is because we
397 -- store the triangles oriented such that their volume is
398 -- positive. If T and T-tilde share \<v0,v1,v3\> and v2,v2-tilde point
399 -- in opposite directions, one of them has to have negative volume!
400 prop_c1200_identity2 :: Cube -> Bool
401 prop_c1200_identity2 cube =
402 c t0 1 2 0 0 ~= (c t0 1 1 1 0 + c t1 1 1 0 1) / 2
403 where
404 t0 = tetrahedron0 cube
405 t1 = tetrahedron1 cube
406
407
408 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
409 -- fourth indices of c-t1 have been switched. This is because we
410 -- store the triangles oriented such that their volume is
411 -- positive. If T and T-tilde share \<v0,v1,v3\> and v2,v2-tilde point
412 -- in opposite directions, one of them has to have negative volume!
413 prop_c2100_identity2 :: Cube -> Bool
414 prop_c2100_identity2 cube =
415 c t0 2 1 0 0 ~= (c t0 2 0 1 0 + c t1 2 0 0 1) / 2
416 where
417 t0 = tetrahedron0 cube
418 t1 = tetrahedron1 cube
419
420
421 prop_t0_shares_edge_with_t6 :: Cube -> Bool
422 prop_t0_shares_edge_with_t6 cube =
423 (v2 t0) == (v3 t6) && (v3 t0) == (v2 t6)
424 where
425 t0 = tetrahedron0 cube
426 t6 = tetrahedron6 cube
427
428
429 -- | Given in Sorokina and Zeilfelder, p. 79.
430 prop_c3000_identity :: Cube -> Bool
431 prop_c3000_identity cube =
432 c t0 3 0 0 0 ~= c t0 2 1 0 0 + c t6 2 1 0 0 - ((c t0 2 0 1 0 + c t0 2 0 0 1)/ 2)
433 where
434 t0 = tetrahedron0 cube
435 t6 = tetrahedron6 cube
436
437
438 -- | Given in Sorokina and Zeilfelder, p. 79.
439 prop_c2010_identity :: Cube -> Bool
440 prop_c2010_identity cube =
441 c t0 2 0 1 0 ~= c t0 1 1 1 0 + c t6 1 1 1 0 - ((c t0 1 0 2 0 + c t0 1 0 1 1)/ 2)
442 where
443 t0 = tetrahedron0 cube
444 t6 = tetrahedron6 cube
445
446
447 -- | Given in Sorokina and Zeilfelder, p. 79.
448 prop_c2001_identity :: Cube -> Bool
449 prop_c2001_identity cube =
450 c t0 2 0 0 1 ~= c t0 1 1 0 1 + c t6 1 1 0 1 - ((c t0 1 0 0 2 + c t0 1 0 1 1)/ 2)
451 where
452 t0 = tetrahedron0 cube
453 t6 = tetrahedron6 cube
454
455 -- | Given in Sorokina and Zeilfelder, p. 79.
456 prop_c1020_identity :: Cube -> Bool
457 prop_c1020_identity cube =
458 c t0 1 0 2 0 ~= c t0 0 1 2 0 + c t6 0 1 2 0 - ((c t0 0 0 3 0 + c t0 0 0 2 1)/ 2)
459 where
460 t0 = tetrahedron0 cube
461 t6 = tetrahedron6 cube
462
463
464 -- | Given in Sorokina and Zeilfelder, p. 79.
465 prop_c1002_identity :: Cube -> Bool
466 prop_c1002_identity cube =
467 c t0 1 0 0 2 ~= c t0 0 1 0 2 + c t6 0 1 0 2 - ((c t0 0 0 0 3 + c t0 0 0 1 2)/ 2)
468 where
469 t0 = tetrahedron0 cube
470 t6 = tetrahedron6 cube
471
472
473 -- | Given in Sorokina and Zeilfelder, p. 79.
474 prop_c1011_identity :: Cube -> Bool
475 prop_c1011_identity cube =
476 c t0 1 0 1 1 ~= c t0 0 1 1 1 + c t6 0 1 1 1 - ((c t0 0 0 1 2 + c t0 0 0 2 1)/ 2)
477 where
478 t0 = tetrahedron0 cube
479 t6 = tetrahedron6 cube
480
481
482
483 -- | Given in Sorokina and Zeilfelder, p. 78.
484 -- prop_cijk1_identity :: Cube -> Bool
485 -- prop_cijk1_identity cube =
486 -- and [ c t0 i j k 1 ~=
487 -- (c t1 (i+1) j k 0) * ((b0 t0) (v3 t1)) +
488 -- (c t1 i (j+1) k 0) * ((b1 t0) (v3 t1)) +
489 -- (c t1 i j (k+1) 0) * ((b2 t0) (v3 t1)) +
490 -- (c t1 i j k 1) * ((b3 t0) (v3 t1)) | i <- [0..2],
491 -- j <- [0..2],
492 -- k <- [0..2],
493 -- i + j + k == 2]
494 -- where
495 -- t0 = tetrahedron0 cube
496 -- t1 = tetrahedron1 cube