From: Michael Orlitzky Date: Fri, 2 Sep 2011 13:15:12 +0000 (-0400) Subject: Make test_trilinear9x9x9_reproduced slow again. X-Git-Tag: 0.0.1~181 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=ae48be1ae233be1bd3632a63febecd3ea7af1f61;p=spline3.git Make test_trilinear9x9x9_reproduced slow again. Add a new failing test: prop_cube_indices_never_go_out_of_bounds. --- diff --git a/src/Tests/Grid.hs b/src/Tests/Grid.hs index 53b4683..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 @@ -191,8 +194,6 @@ test_zeros_reproduced = -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one. --- Use (t <- tetrahedra c0) for a much slower but comprehensive --- test. test_trilinear9x9x9_reproduced :: Assertion test_trilinear9x9x9_reproduced = assertTrue "trilinear 9x9x9 is reproduced correctly" $ @@ -200,7 +201,7 @@ test_trilinear9x9x9_reproduced = | i <- [0..8], j <- [0..8], k <- [0..8], - t <- [head $ tetrahedra c0], + t <- tetrahedra c0, let p = polynomial t, let i' = (fromIntegral i) * 0.5, let j' = (fromIntegral j) * 0.5, @@ -228,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