]> gitweb.michael.orlitzky.com - spline3.git/blobdiff - src/Tests/Grid.hs
Move the Cardinal tests into the Cardinal module.
[spline3.git] / src / Tests / Grid.hs
index e30ae4a6d4f124228eae0173e5e024f46fcb90ba..a8bc68543a03b4423884b8abcf9deb95295a6f28 100644 (file)
@@ -4,6 +4,8 @@ where
 import Test.Framework (Test, testGroup)
 import Test.Framework.Providers.HUnit (testCase)
 import Test.HUnit
+import Test.QuickCheck
+
 
 import Assertions
 import Comparisons
@@ -14,6 +16,7 @@ import Grid
 import Point (Point)
 import Tetrahedron
 import ThreeDimensional
+import Values (dims)
 
 
 -- | Check all coefficients of tetrahedron0 belonging to the cube
@@ -226,3 +229,32 @@ test_tetrahedra_collision_sensitivity =
     c = cube_at g 0 17 1
     p = (0, 16.75, 0.5) :: Point
     t15 = tetrahedron15 c
+
+
+prop_cube_indices_never_go_out_of_bounds :: Grid -> Gen Bool
+prop_cube_indices_never_go_out_of_bounds g =
+  do
+    let delta = Grid.h g
+    let coordmin = negate (delta/2)
+
+    let (xsize, ysize, zsize) = dims $ function_values g
+    let xmax = delta*(fromIntegral xsize) - (delta/2)
+    let ymax = delta*(fromIntegral ysize) - (delta/2)
+    let zmax = delta*(fromIntegral zsize) - (delta/2)
+
+    x <- choose (coordmin, xmax)
+    y <- choose (coordmin, ymax)
+    z <- choose (coordmin, zmax)
+
+    let p = (x,y,z) :: Point
+    let idx_x = calculate_containing_cube_coordinate g x
+    let idx_y = calculate_containing_cube_coordinate g y
+    let idx_z = calculate_containing_cube_coordinate g z
+
+    return $
+      idx_x >= 0 &&
+      idx_x <= xsize - 1 &&
+      idx_y >= 0 &&
+      idx_y <= ysize - 1 &&
+      idx_z >= 0 &&
+      idx_z <= zsize - 1