]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cube.hs
b78888434d7cfc03a2956c2e30b8b06509dc853d
[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(FunctionValues))
9 import Tests.FunctionValues
10 import Tetrahedron (v0, volume)
11
12 instance Arbitrary Cube where
13 arbitrary = do
14 (Positive h') <- arbitrary :: Gen (Positive Double)
15 i' <- choose (coordmin, coordmax)
16 j' <- choose (coordmin, coordmax)
17 k' <- choose (coordmin, coordmax)
18 fv' <- arbitrary :: Gen FunctionValues
19 return (Cube h' i' j' k' fv')
20 where
21 coordmin = -268435456 -- -(2^29 / 2)
22 coordmax = 268435456 -- +(2^29 / 2)
23
24
25 -- Quickcheck tests.
26
27 -- | Since the grid size is necessarily positive, all tetrahedrons
28 -- (which comprise cubes of positive volume) must have positive volume
29 -- as well.
30 prop_all_volumes_positive :: Cube -> Bool
31 prop_all_volumes_positive c =
32 null nonpositive_volumes
33 where
34 ts = tetrahedrons c
35 volumes = map volume ts
36 nonpositive_volumes = filter (<= 0) volumes
37
38 -- | In fact, since all of the tetrahedra are identical, we should
39 -- already know their volumes. There's 24 tetrahedra to a cube, so
40 -- we'd expect the volume of each one to be (1/24)*h^3.
41 prop_all_volumes_exact :: Cube -> Bool
42 prop_all_volumes_exact c =
43 volume t ~= (1/24)*(delta^(3::Int))
44 where
45 t = head $ tetrahedrons c
46 delta = h c
47
48 -- | All tetrahedron should have their v0 located at the center of the cube.
49 prop_v0_all_equal :: Cube -> Bool
50 prop_v0_all_equal c = (v0 t0) == (v0 t1)
51 where
52 t0 = head (tetrahedrons c) -- Doesn't matter which two we choose.
53 t1 = head $ tail (tetrahedrons c)
54
55
56 -- | This pretty much repeats the prop_all_volumes_positive property,
57 -- but will let me know which tetrahedrons's vertices are disoriented.
58 prop_tetrahedron0_volumes_positive :: Cube -> Bool
59 prop_tetrahedron0_volumes_positive c =
60 volume (tetrahedron0 c) > 0
61
62 -- | This pretty much repeats the prop_all_volumes_positive property,
63 -- but will let me know which tetrahedrons's vertices are disoriented.
64 prop_tetrahedron1_volumes_positive :: Cube -> Bool
65 prop_tetrahedron1_volumes_positive c =
66 volume (tetrahedron1 c) > 0
67
68 -- | This pretty much repeats the prop_all_volumes_positive property,
69 -- but will let me know which tetrahedrons's vertices are disoriented.
70 prop_tetrahedron2_volumes_positive :: Cube -> Bool
71 prop_tetrahedron2_volumes_positive c =
72 volume (tetrahedron2 c) > 0
73
74 -- | This pretty much repeats the prop_all_volumes_positive property,
75 -- but will let me know which tetrahedrons's vertices are disoriented.
76 prop_tetrahedron3_volumes_positive :: Cube -> Bool
77 prop_tetrahedron3_volumes_positive c =
78 volume (tetrahedron3 c) > 0
79
80 -- | This pretty much repeats the prop_all_volumes_positive property,
81 -- but will let me know which tetrahedrons's vertices are disoriented.
82 prop_tetrahedron4_volumes_positive :: Cube -> Bool
83 prop_tetrahedron4_volumes_positive c =
84 volume (tetrahedron4 c) > 0
85
86 -- | This pretty much repeats the prop_all_volumes_positive property,
87 -- but will let me know which tetrahedrons's vertices are disoriented.
88 prop_tetrahedron5_volumes_positive :: Cube -> Bool
89 prop_tetrahedron5_volumes_positive c =
90 volume (tetrahedron5 c) > 0
91
92 -- | This pretty much repeats the prop_all_volumes_positive property,
93 -- but will let me know which tetrahedrons's vertices are disoriented.
94 prop_tetrahedron6_volumes_positive :: Cube -> Bool
95 prop_tetrahedron6_volumes_positive c =
96 volume (tetrahedron6 c) > 0
97
98 -- | This pretty much repeats the prop_all_volumes_positive property,
99 -- but will let me know which tetrahedrons's vertices are disoriented.
100 prop_tetrahedron7_volumes_positive :: Cube -> Bool
101 prop_tetrahedron7_volumes_positive c =
102 volume (tetrahedron7 c) > 0