]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cube.hs
Re-enable the prop_all_volumes_positive check and add some new ones.
[spline3.git] / src / Tests / Cube.hs
1 module Tests.Cube
2 where
3
4 import Test.QuickCheck
5
6 import Cube
7 import FunctionValues (FunctionValues(FunctionValues))
8 import Tests.FunctionValues
9 import Tetrahedron (v0, volume)
10
11 instance Arbitrary Cube where
12 arbitrary = do
13 (Positive h') <- arbitrary :: Gen (Positive Double)
14 i' <- choose (coordmin, coordmax)
15 j' <- choose (coordmin, coordmax)
16 k' <- choose (coordmin, coordmax)
17 fv' <- arbitrary :: Gen FunctionValues
18 return (Cube h' i' j' k' fv')
19 where
20 coordmin = -268435456 -- -(2^29 / 2)
21 coordmax = 268435456 -- +(2^29 / 2)
22
23
24 -- Quickcheck tests.
25
26 -- | Since the grid size is necessarily positive, all tetrahedrons
27 -- (which comprise cubes of positive volume) must have positive volume
28 -- as well.
29 prop_all_volumes_positive :: Cube -> Property
30 prop_all_volumes_positive c =
31 (delta > 0) ==> (null nonpositive_volumes)
32 where
33 delta = h c
34 ts = tetrahedrons c
35 volumes = map volume ts
36 nonpositive_volumes = filter (<= 0) volumes
37
38 -- | All tetrahedron should have their v0 located at the center of the cube.
39 prop_v0_all_equal :: Cube -> Bool
40 prop_v0_all_equal c = (v0 t0) == (v0 t1)
41 where
42 t0 = head (tetrahedrons c) -- Doesn't matter which two we choose.
43 t1 = head $ tail (tetrahedrons c)
44
45
46 -- | This pretty much repeats the prop_all_volumes_positive property,
47 -- but will let me know which face's vertices are disoriented.
48 prop_front_face_volumes_positive :: Cube -> Property
49 prop_front_face_volumes_positive c =
50 (delta > 0) ==> (null nonpositive_volumes)
51 where
52 delta = h c
53 ts = [tetrahedron0 c, tetrahedron1 c, tetrahedron2 c, tetrahedron3 c]
54 volumes = map volume ts
55 nonpositive_volumes = filter (<= 0) volumes
56
57
58 -- | This pretty much repeats the prop_all_volumes_positive property,
59 -- but will let me know which face's vertices are disoriented.
60 prop_top_face_volumes_positive :: Cube -> Property
61 prop_top_face_volumes_positive c =
62 (delta > 0) ==> (null nonpositive_volumes)
63 where
64 delta = h c
65 ts = [tetrahedron4 c, tetrahedron5 c, tetrahedron6 c, tetrahedron7 c]
66 volumes = map volume ts
67 nonpositive_volumes = filter (<= 0) volumes