4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
12 import Cube hiding (i, j, k)
14 import FunctionValues (value_at)
18 import ThreeDimensional
22 -- | Check all coefficients of tetrahedron0 belonging to the cube
23 -- centered on (1,1,1) with a grid constructed from the trilinear
24 -- values. See example one in the paper.
26 -- We also verify that the four vertices on face0 of the cube are
27 -- in the correct location.
29 trilinear_c0_t0_tests :: Test.Framework.Test
30 trilinear_c0_t0_tests =
31 testGroup "trilinear c0 t0"
32 [testGroup "coefficients"
33 [testCase "c0030 is correct" test_trilinear_c0030,
34 testCase "c0003 is correct" test_trilinear_c0003,
35 testCase "c0021 is correct" test_trilinear_c0021,
36 testCase "c0012 is correct" test_trilinear_c0012,
37 testCase "c0120 is correct" test_trilinear_c0120,
38 testCase "c0102 is correct" test_trilinear_c0102,
39 testCase "c0111 is correct" test_trilinear_c0111,
40 testCase "c0210 is correct" test_trilinear_c0210,
41 testCase "c0201 is correct" test_trilinear_c0201,
42 testCase "c0300 is correct" test_trilinear_c0300,
43 testCase "c1020 is correct" test_trilinear_c1020,
44 testCase "c1002 is correct" test_trilinear_c1002,
45 testCase "c1011 is correct" test_trilinear_c1011,
46 testCase "c1110 is correct" test_trilinear_c1110,
47 testCase "c1101 is correct" test_trilinear_c1101,
48 testCase "c1200 is correct" test_trilinear_c1200,
49 testCase "c2010 is correct" test_trilinear_c2010,
50 testCase "c2001 is correct" test_trilinear_c2001,
51 testCase "c2100 is correct" test_trilinear_c2100,
52 testCase "c3000 is correct" test_trilinear_c3000],
54 testGroup "face0 vertices"
55 [testCase "v0 is correct" test_trilinear_f0_t0_v0,
56 testCase "v1 is correct" test_trilinear_f0_t0_v1,
57 testCase "v2 is correct" test_trilinear_f0_t0_v2,
58 testCase "v3 is correct" test_trilinear_f0_t0_v3]
61 g = make_grid 1 trilinear
62 cube = cube_at g 1 1 1
65 test_trilinear_c0030 :: Assertion
66 test_trilinear_c0030 =
67 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
69 test_trilinear_c0003 :: Assertion
70 test_trilinear_c0003 =
71 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
73 test_trilinear_c0021 :: Assertion
74 test_trilinear_c0021 =
75 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
77 test_trilinear_c0012 :: Assertion
78 test_trilinear_c0012 =
79 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
81 test_trilinear_c0120 :: Assertion
82 test_trilinear_c0120 =
83 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
85 test_trilinear_c0102 :: Assertion
86 test_trilinear_c0102 =
87 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
89 test_trilinear_c0111 :: Assertion
90 test_trilinear_c0111 =
91 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
93 test_trilinear_c0210 :: Assertion
94 test_trilinear_c0210 =
95 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
97 test_trilinear_c0201 :: Assertion
98 test_trilinear_c0201 =
99 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
101 test_trilinear_c0300 :: Assertion
102 test_trilinear_c0300 =
103 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
105 test_trilinear_c1020 :: Assertion
106 test_trilinear_c1020 =
107 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
109 test_trilinear_c1002 :: Assertion
110 test_trilinear_c1002 =
111 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
113 test_trilinear_c1011 :: Assertion
114 test_trilinear_c1011 =
115 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
117 test_trilinear_c1110 :: Assertion
118 test_trilinear_c1110 =
119 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
121 test_trilinear_c1101 :: Assertion
122 test_trilinear_c1101 =
123 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
125 test_trilinear_c1200 :: Assertion
126 test_trilinear_c1200 =
127 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
129 test_trilinear_c2010 :: Assertion
130 test_trilinear_c2010 =
131 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
133 test_trilinear_c2001 :: Assertion
134 test_trilinear_c2001 =
135 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
137 test_trilinear_c2100 :: Assertion
138 test_trilinear_c2100 =
139 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
141 test_trilinear_c3000 :: Assertion
142 test_trilinear_c3000 =
143 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
145 test_trilinear_f0_t0_v0 :: Assertion
146 test_trilinear_f0_t0_v0 =
147 assertEqual "v0 is correct" (v0 t) (1, 1, 1)
149 test_trilinear_f0_t0_v1 :: Assertion
150 test_trilinear_f0_t0_v1 =
151 assertEqual "v1 is correct" (v1 t) (0.5, 1, 1)
153 test_trilinear_f0_t0_v2 :: Assertion
154 test_trilinear_f0_t0_v2 =
155 assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
157 test_trilinear_f0_t0_v3 :: Assertion
158 test_trilinear_f0_t0_v3 =
159 assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
162 test_trilinear_reproduced :: Assertion
163 test_trilinear_reproduced =
164 assertTrue "trilinears are reproduced correctly" $
165 and [p (i', j', k') ~= value_at trilinear i j k
170 let p = polynomial t,
171 let i' = fromIntegral i,
172 let j' = fromIntegral j,
173 let k' = fromIntegral k]
175 g = make_grid 1 trilinear
179 test_zeros_reproduced :: Assertion
180 test_zeros_reproduced =
181 assertTrue "the zero function is reproduced correctly" $
182 and [p (i', j', k') ~= value_at zeros i j k
186 let i' = fromIntegral i,
187 let j' = fromIntegral j,
188 let k' = fromIntegral k]
190 g = make_grid 1 zeros
196 -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one.
197 test_trilinear9x9x9_reproduced :: Assertion
198 test_trilinear9x9x9_reproduced =
199 assertTrue "trilinear 9x9x9 is reproduced correctly" $
200 and [p (i', j', k') ~= value_at trilinear9x9x9 i j k
205 let p = polynomial t,
206 let i' = (fromIntegral i) * 0.5,
207 let j' = (fromIntegral j) * 0.5,
208 let k' = (fromIntegral k) * 0.5]
210 g = make_grid 1 trilinear
214 -- | The point 'p' in this test lies on the boundary of tetrahedra 12 and 15.
215 -- However, the 'contains_point' test fails due to some numerical innacuracy.
216 -- This bug should have been fixed by setting a positive tolerance level.
218 -- Example from before the fix:
220 -- > b0 (tetrahedron15 c) p
221 -- -3.4694469519536365e-18
223 test_tetrahedra_collision_sensitivity :: Assertion
224 test_tetrahedra_collision_sensitivity =
225 assertTrue "tetrahedron collision tests isn't too sensitive" $
228 g = make_grid 1 naturals_1d
230 p = (0, 16.75, 0.5) :: Point
231 t15 = tetrahedron15 c
234 prop_cube_indices_never_go_out_of_bounds :: Grid -> Gen Bool
235 prop_cube_indices_never_go_out_of_bounds g =
238 let coordmin = negate (delta/2)
240 let (xsize, ysize, zsize) = dims $ function_values g
241 let xmax = delta*(fromIntegral xsize) - (delta/2)
242 let ymax = delta*(fromIntegral ysize) - (delta/2)
243 let zmax = delta*(fromIntegral zsize) - (delta/2)
245 x <- choose (coordmin, xmax)
246 y <- choose (coordmin, ymax)
247 z <- choose (coordmin, zmax)
249 let p = (x,y,z) :: Point
250 let idx_x = calculate_containing_cube_coordinate g x
251 let idx_y = calculate_containing_cube_coordinate g y
252 let idx_z = calculate_containing_cube_coordinate g z
256 idx_x <= xsize - 1 &&
258 idx_y <= ysize - 1 &&