]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Grid.hs
d06e1e96732a07f1852a8e4913e050f49b616cd5
[spline3.git] / src / Tests / Grid.hs
1 module Tests.Grid
2 where
3
4 import Test.Framework (Test, testGroup)
5 import Test.Framework.Providers.HUnit (testCase)
6 import Test.HUnit
7
8 import Assertions
9 import Comparisons
10 import Cube hiding (i, j, k)
11 import Examples
12 import FunctionValues (value_at)
13 import Grid
14 import Point (Point)
15 import Tetrahedron
16 import ThreeDimensional
17
18
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]
45 where
46 g = make_grid 1 trilinear
47 cube = cube_at g 1 1 1
48 t = tetrahedron0 cube
49
50 test_trilinear_c0030 :: Assertion
51 test_trilinear_c0030 =
52 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
53
54 test_trilinear_c0003 :: Assertion
55 test_trilinear_c0003 =
56 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
57
58 test_trilinear_c0021 :: Assertion
59 test_trilinear_c0021 =
60 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
61
62 test_trilinear_c0012 :: Assertion
63 test_trilinear_c0012 =
64 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
65
66 test_trilinear_c0120 :: Assertion
67 test_trilinear_c0120 =
68 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
69
70 test_trilinear_c0102 :: Assertion
71 test_trilinear_c0102 =
72 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
73
74 test_trilinear_c0111 :: Assertion
75 test_trilinear_c0111 =
76 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
77
78 test_trilinear_c0210 :: Assertion
79 test_trilinear_c0210 =
80 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
81
82 test_trilinear_c0201 :: Assertion
83 test_trilinear_c0201 =
84 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
85
86 test_trilinear_c0300 :: Assertion
87 test_trilinear_c0300 =
88 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
89
90 test_trilinear_c1020 :: Assertion
91 test_trilinear_c1020 =
92 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
93
94 test_trilinear_c1002 :: Assertion
95 test_trilinear_c1002 =
96 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
97
98 test_trilinear_c1011 :: Assertion
99 test_trilinear_c1011 =
100 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
101
102 test_trilinear_c1110 :: Assertion
103 test_trilinear_c1110 =
104 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
105
106 test_trilinear_c1101 :: Assertion
107 test_trilinear_c1101 =
108 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
109
110 test_trilinear_c1200 :: Assertion
111 test_trilinear_c1200 =
112 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
113
114 test_trilinear_c2010 :: Assertion
115 test_trilinear_c2010 =
116 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
117
118 test_trilinear_c2001 :: Assertion
119 test_trilinear_c2001 =
120 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
121
122 test_trilinear_c2100 :: Assertion
123 test_trilinear_c2100 =
124 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
125
126 test_trilinear_c3000 :: Assertion
127 test_trilinear_c3000 =
128 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
129
130
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)
137 where
138 g = make_grid 1 trilinear
139 cube = cube_at g 1 1 1
140 t = tetrahedron0 cube
141
142
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)
149 where
150 g = make_grid 1 trilinear
151 cube = cube_at g 1 1 1
152 t = tetrahedron0 cube
153
154
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)
161 where
162 g = make_grid 1 trilinear
163 cube = cube_at g 1 1 1
164 t = tetrahedron0 cube
165
166
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)
173 where
174 g = make_grid 1 trilinear
175 cube = cube_at g 1 1 1
176 t = tetrahedron0 cube
177
178
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
183 | i <- [0..2],
184 j <- [0..2],
185 k <- [0..2],
186 t <- tetrahedra c0,
187 let p = polynomial t,
188 let i' = fromIntegral i,
189 let j' = fromIntegral j,
190 let k' = fromIntegral k]
191 where
192 g = make_grid 1 trilinear
193 c0 = cube_at g 1 1 1
194
195
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
200 | i <- [0..2],
201 j <- [0..2],
202 k <- [0..2],
203 let i' = fromIntegral i,
204 let j' = fromIntegral j,
205 let k' = fromIntegral k]
206 where
207 g = make_grid 1 zeros
208 c0 = cube_at g 1 1 1
209 t0 = tetrahedron0 c0
210 p = polynomial t0
211
212
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
218 | i <- [0..8],
219 j <- [0..8],
220 k <- [0..8],
221 t <- tetrahedra c0,
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]
226 where
227 g = make_grid 1 trilinear
228 c0 = cube_at g 1 1 1
229
230
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.
234 --
235 -- Example from before the fix:
236 --
237 -- > b0 (tetrahedron15 c) p
238 -- -3.4694469519536365e-18
239 --
240 test_tetrahedra_collision_sensitivity :: Assertion
241 test_tetrahedra_collision_sensitivity =
242 assertTrue "tetrahedron collision tests isn't too sensitive" $
243 contains_point t15 p
244 where
245 g = make_grid 1 naturals_1d
246 c = cube_at g 0 17 1
247 p = (0, 16.75, 0.5) :: Point
248 t15 = tetrahedron15 c