X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTests%2FGrid.hs;h=a8bc68543a03b4423884b8abcf9deb95295a6f28;hb=3d197ab1a23d654d60617db6559daed195f1e016;hp=e30ae4a6d4f124228eae0173e5e024f46fcb90ba;hpb=f523e553956c11962c25dac6e9521aeb7f13025e;p=spline3.git diff --git a/src/Tests/Grid.hs b/src/Tests/Grid.hs index e30ae4a..a8bc685 100644 --- a/src/Tests/Grid.hs +++ b/src/Tests/Grid.hs @@ -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