4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
10 import Cube hiding (i, j, k)
12 import FunctionValues (value_at)
16 import ThreeDimensional
19 -- | Check all coefficients of tetrahedron0 belonging to the cube
20 -- centered on (1,1,1) with a grid constructed from the trilinear
21 -- values. See example one in the paper.
22 trilinear_c0_t0_coefficient_tests :: Test.Framework.Test
23 trilinear_c0_t0_coefficient_tests =
24 testGroup "trilinear c0 t0 coefficients" $
25 [testCase "c0030 is correct" test_trilinear_c0030,
26 testCase "c0003 is correct" test_trilinear_c0003,
27 testCase "c0021 is correct" test_trilinear_c0021,
28 testCase "c0012 is correct" test_trilinear_c0012,
29 testCase "c0120 is correct" test_trilinear_c0120,
30 testCase "c0102 is correct" test_trilinear_c0102,
31 testCase "c0111 is correct" test_trilinear_c0111,
32 testCase "c0210 is correct" test_trilinear_c0210,
33 testCase "c0201 is correct" test_trilinear_c0201,
34 testCase "c0300 is correct" test_trilinear_c0300,
35 testCase "c1020 is correct" test_trilinear_c1020,
36 testCase "c1002 is correct" test_trilinear_c1002,
37 testCase "c1011 is correct" test_trilinear_c1011,
38 testCase "c1110 is correct" test_trilinear_c1110,
39 testCase "c1101 is correct" test_trilinear_c1101,
40 testCase "c1200 is correct" test_trilinear_c1200,
41 testCase "c2010 is correct" test_trilinear_c2010,
42 testCase "c2001 is correct" test_trilinear_c2001,
43 testCase "c2100 is correct" test_trilinear_c2100,
44 testCase "c3000 is correct" test_trilinear_c3000]
46 g = make_grid 1 trilinear
47 cube = cube_at g 1 1 1
50 test_trilinear_c0030 :: Assertion
51 test_trilinear_c0030 =
52 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
54 test_trilinear_c0003 :: Assertion
55 test_trilinear_c0003 =
56 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
58 test_trilinear_c0021 :: Assertion
59 test_trilinear_c0021 =
60 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
62 test_trilinear_c0012 :: Assertion
63 test_trilinear_c0012 =
64 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
66 test_trilinear_c0120 :: Assertion
67 test_trilinear_c0120 =
68 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
70 test_trilinear_c0102 :: Assertion
71 test_trilinear_c0102 =
72 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
74 test_trilinear_c0111 :: Assertion
75 test_trilinear_c0111 =
76 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
78 test_trilinear_c0210 :: Assertion
79 test_trilinear_c0210 =
80 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
82 test_trilinear_c0201 :: Assertion
83 test_trilinear_c0201 =
84 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
86 test_trilinear_c0300 :: Assertion
87 test_trilinear_c0300 =
88 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
90 test_trilinear_c1020 :: Assertion
91 test_trilinear_c1020 =
92 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
94 test_trilinear_c1002 :: Assertion
95 test_trilinear_c1002 =
96 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
98 test_trilinear_c1011 :: Assertion
99 test_trilinear_c1011 =
100 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
102 test_trilinear_c1110 :: Assertion
103 test_trilinear_c1110 =
104 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
106 test_trilinear_c1101 :: Assertion
107 test_trilinear_c1101 =
108 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
110 test_trilinear_c1200 :: Assertion
111 test_trilinear_c1200 =
112 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
114 test_trilinear_c2010 :: Assertion
115 test_trilinear_c2010 =
116 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
118 test_trilinear_c2001 :: Assertion
119 test_trilinear_c2001 =
120 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
122 test_trilinear_c2100 :: Assertion
123 test_trilinear_c2100 =
124 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
126 test_trilinear_c3000 :: Assertion
127 test_trilinear_c3000 =
128 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
131 -- | Make sure that v0 of tetrahedron0 belonging to the cube centered
132 -- on (1,1,1) with a grid constructed from the trilinear values
133 -- winds up in the right place. See example one in the paper.
134 test_trilinear_f0_t0_v0 :: Assertion
135 test_trilinear_f0_t0_v0 =
136 assertEqual "v0 is correct" (v0 t) (1, 1, 1)
138 g = make_grid 1 trilinear
139 cube = cube_at g 1 1 1
140 t = tetrahedron0 cube
143 -- | Make sure that v1 of tetrahedron0 belonging to the cube centered
144 -- on (1,1,1) with a grid constructed from the trilinear values
145 -- winds up in the right place. See example one in the paper.
146 test_trilinear_f0_t0_v1 :: Assertion
147 test_trilinear_f0_t0_v1 =
148 assertEqual "v1 is correct" (v1 t) (0.5, 1, 1)
150 g = make_grid 1 trilinear
151 cube = cube_at g 1 1 1
152 t = tetrahedron0 cube
155 -- | Make sure that v2 of tetrahedron0 belonging to the cube centered
156 -- on (1,1,1) with a grid constructed from the trilinear values
157 -- winds up in the right place. See example one in the paper.
158 test_trilinear_f0_t0_v2 :: Assertion
159 test_trilinear_f0_t0_v2 =
160 assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
162 g = make_grid 1 trilinear
163 cube = cube_at g 1 1 1
164 t = tetrahedron0 cube
167 -- | Make sure that v3 of tetrahedron0 belonging to the cube centered
168 -- on (1,1,1) with a grid constructed from the trilinear values
169 -- winds up in the right place. See example one in the paper.
170 test_trilinear_f0_t0_v3 :: Assertion
171 test_trilinear_f0_t0_v3 =
172 assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
174 g = make_grid 1 trilinear
175 cube = cube_at g 1 1 1
176 t = tetrahedron0 cube
179 test_trilinear_reproduced :: Assertion
180 test_trilinear_reproduced =
181 assertTrue "trilinears are reproduced correctly" $
182 and [p (i', j', k') ~= value_at trilinear i j k
187 let p = polynomial t,
188 let i' = fromIntegral i,
189 let j' = fromIntegral j,
190 let k' = fromIntegral k]
192 g = make_grid 1 trilinear
196 test_zeros_reproduced :: Assertion
197 test_zeros_reproduced =
198 assertTrue "the zero function is reproduced correctly" $
199 and [p (i', j', k') ~= value_at zeros i j k
203 let i' = fromIntegral i,
204 let j' = fromIntegral j,
205 let k' = fromIntegral k]
207 g = make_grid 1 zeros
213 -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one.
214 test_trilinear9x9x9_reproduced :: Assertion
215 test_trilinear9x9x9_reproduced =
216 assertTrue "trilinear 9x9x9 is reproduced correctly" $
217 and [p (i', j', k') ~= value_at trilinear9x9x9 i j k
222 let p = polynomial t,
223 let i' = (fromIntegral i) * 0.5,
224 let j' = (fromIntegral j) * 0.5,
225 let k' = (fromIntegral k) * 0.5]
227 g = make_grid 1 trilinear
231 -- | The point 'p' in this test lies on the boundary of tetrahedra 12 and 15.
232 -- However, the 'contains_point' test fails due to some numerical innacuracy.
233 -- This bug should have been fixed by setting a positive tolerance level.
235 -- Example from before the fix:
237 -- > b0 (tetrahedron15 c) p
238 -- -3.4694469519536365e-18
240 test_tetrahedra_collision_sensitivity :: Assertion
241 test_tetrahedra_collision_sensitivity =
242 assertTrue "tetrahedron collision tests isn't too sensitive" $
245 g = make_grid 1 naturals_1d
247 p = (0, 16.75, 0.5) :: Point
248 t15 = tetrahedron15 c