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.
23 -- We also verify that the four vertices on face0 of the cube are
24 -- in the correct location.
26 trilinear_c0_t0_tests :: Test.Framework.Test
27 trilinear_c0_t0_tests =
28 testGroup "trilinear c0 t0"
29 [testGroup "coefficients"
30 [testCase "c0030 is correct" test_trilinear_c0030,
31 testCase "c0003 is correct" test_trilinear_c0003,
32 testCase "c0021 is correct" test_trilinear_c0021,
33 testCase "c0012 is correct" test_trilinear_c0012,
34 testCase "c0120 is correct" test_trilinear_c0120,
35 testCase "c0102 is correct" test_trilinear_c0102,
36 testCase "c0111 is correct" test_trilinear_c0111,
37 testCase "c0210 is correct" test_trilinear_c0210,
38 testCase "c0201 is correct" test_trilinear_c0201,
39 testCase "c0300 is correct" test_trilinear_c0300,
40 testCase "c1020 is correct" test_trilinear_c1020,
41 testCase "c1002 is correct" test_trilinear_c1002,
42 testCase "c1011 is correct" test_trilinear_c1011,
43 testCase "c1110 is correct" test_trilinear_c1110,
44 testCase "c1101 is correct" test_trilinear_c1101,
45 testCase "c1200 is correct" test_trilinear_c1200,
46 testCase "c2010 is correct" test_trilinear_c2010,
47 testCase "c2001 is correct" test_trilinear_c2001,
48 testCase "c2100 is correct" test_trilinear_c2100,
49 testCase "c3000 is correct" test_trilinear_c3000],
51 testGroup "face0 vertices"
52 [testCase "v0 is correct" test_trilinear_f0_t0_v0,
53 testCase "v1 is correct" test_trilinear_f0_t0_v1,
54 testCase "v2 is correct" test_trilinear_f0_t0_v2,
55 testCase "v3 is correct" test_trilinear_f0_t0_v3]
58 g = make_grid 1 trilinear
59 cube = cube_at g 1 1 1
62 test_trilinear_c0030 :: Assertion
63 test_trilinear_c0030 =
64 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
66 test_trilinear_c0003 :: Assertion
67 test_trilinear_c0003 =
68 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
70 test_trilinear_c0021 :: Assertion
71 test_trilinear_c0021 =
72 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
74 test_trilinear_c0012 :: Assertion
75 test_trilinear_c0012 =
76 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
78 test_trilinear_c0120 :: Assertion
79 test_trilinear_c0120 =
80 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
82 test_trilinear_c0102 :: Assertion
83 test_trilinear_c0102 =
84 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
86 test_trilinear_c0111 :: Assertion
87 test_trilinear_c0111 =
88 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
90 test_trilinear_c0210 :: Assertion
91 test_trilinear_c0210 =
92 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
94 test_trilinear_c0201 :: Assertion
95 test_trilinear_c0201 =
96 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
98 test_trilinear_c0300 :: Assertion
99 test_trilinear_c0300 =
100 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
102 test_trilinear_c1020 :: Assertion
103 test_trilinear_c1020 =
104 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
106 test_trilinear_c1002 :: Assertion
107 test_trilinear_c1002 =
108 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
110 test_trilinear_c1011 :: Assertion
111 test_trilinear_c1011 =
112 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
114 test_trilinear_c1110 :: Assertion
115 test_trilinear_c1110 =
116 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
118 test_trilinear_c1101 :: Assertion
119 test_trilinear_c1101 =
120 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
122 test_trilinear_c1200 :: Assertion
123 test_trilinear_c1200 =
124 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
126 test_trilinear_c2010 :: Assertion
127 test_trilinear_c2010 =
128 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
130 test_trilinear_c2001 :: Assertion
131 test_trilinear_c2001 =
132 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
134 test_trilinear_c2100 :: Assertion
135 test_trilinear_c2100 =
136 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
138 test_trilinear_c3000 :: Assertion
139 test_trilinear_c3000 =
140 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
142 test_trilinear_f0_t0_v0 :: Assertion
143 test_trilinear_f0_t0_v0 =
144 assertEqual "v0 is correct" (v0 t) (1, 1, 1)
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 test_trilinear_f0_t0_v2 :: Assertion
151 test_trilinear_f0_t0_v2 =
152 assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
154 test_trilinear_f0_t0_v3 :: Assertion
155 test_trilinear_f0_t0_v3 =
156 assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
159 test_trilinear_reproduced :: Assertion
160 test_trilinear_reproduced =
161 assertTrue "trilinears are reproduced correctly" $
162 and [p (i', j', k') ~= value_at trilinear i j k
167 let p = polynomial t,
168 let i' = fromIntegral i,
169 let j' = fromIntegral j,
170 let k' = fromIntegral k]
172 g = make_grid 1 trilinear
176 test_zeros_reproduced :: Assertion
177 test_zeros_reproduced =
178 assertTrue "the zero function is reproduced correctly" $
179 and [p (i', j', k') ~= value_at zeros i j k
183 let i' = fromIntegral i,
184 let j' = fromIntegral j,
185 let k' = fromIntegral k]
187 g = make_grid 1 zeros
193 -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one.
194 -- Use (t <- tetrahedra c0) for a much slower but comprehensive
196 test_trilinear9x9x9_reproduced :: Assertion
197 test_trilinear9x9x9_reproduced =
198 assertTrue "trilinear 9x9x9 is reproduced correctly" $
199 and [p (i', j', k') ~= value_at trilinear9x9x9 i j k
203 t <- [head $ tetrahedra c0],
204 let p = polynomial t,
205 let i' = (fromIntegral i) * 0.5,
206 let j' = (fromIntegral j) * 0.5,
207 let k' = (fromIntegral k) * 0.5]
209 g = make_grid 1 trilinear
213 -- | The point 'p' in this test lies on the boundary of tetrahedra 12 and 15.
214 -- However, the 'contains_point' test fails due to some numerical innacuracy.
215 -- This bug should have been fixed by setting a positive tolerance level.
217 -- Example from before the fix:
219 -- > b0 (tetrahedron15 c) p
220 -- -3.4694469519536365e-18
222 test_tetrahedra_collision_sensitivity :: Assertion
223 test_tetrahedra_collision_sensitivity =
224 assertTrue "tetrahedron collision tests isn't too sensitive" $
227 g = make_grid 1 naturals_1d
229 p = (0, 16.75, 0.5) :: Point
230 t15 = tetrahedron15 c