]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Grid.hs
Rename "trilinearx2" to "trilinear9x9x9".
[spline3.git] / src / Tests / Grid.hs
1 module Tests.Grid
2 where
3
4 import Data.Maybe (fromJust)
5 import Test.HUnit
6
7 import Assertions
8 import Comparisons
9 import Cube hiding (i, j, k)
10 import Examples
11 import FunctionValues (value_at)
12 import Grid
13 import Tetrahedron
14
15
16 -- | Check the value of c0030 for tetrahedron0 belonging to the
17 -- cube centered on (1,1,1) with a grid constructed from the
18 -- trilinear values. See example one in the paper.
19 test_trilinear_c0030 :: Assertion
20 test_trilinear_c0030 =
21 assertAlmostEqual "c0030 is correct" (c t 0 0 3 0) (17/8)
22 where
23 g = make_grid 1 trilinear
24 cube = fromJust $ cube_at g 1 1 1
25 t = tetrahedron0 cube
26
27
28 -- | Check the value of c0003 for tetrahedron0 belonging to the
29 -- cube centered on (1,1,1) with a grid constructed from the
30 -- trilinear values. See example one in the paper.
31 test_trilinear_c0003 :: Assertion
32 test_trilinear_c0003 =
33 assertAlmostEqual "c0003 is correct" (c t 0 0 0 3) (27/8)
34 where
35 g = make_grid 1 trilinear
36 cube = fromJust $ cube_at g 1 1 1
37 t = tetrahedron0 cube
38
39
40 -- | Check the value of c0021 for tetrahedron0 belonging to the
41 -- cube centered on (1,1,1) with a grid constructed from the
42 -- trilinear values. See example one in the paper.
43 test_trilinear_c0021 :: Assertion
44 test_trilinear_c0021 =
45 assertAlmostEqual "c0021 is correct" (c t 0 0 2 1) (61/24)
46 where
47 g = make_grid 1 trilinear
48 cube = fromJust $ cube_at g 1 1 1
49 t = tetrahedron0 cube
50
51
52 -- | Check the value of c0012 for tetrahedron0 belonging to the
53 -- cube centered on (1,1,1) with a grid constructed from the
54 -- trilinear values. See example one in the paper.
55 test_trilinear_c0012 :: Assertion
56 test_trilinear_c0012 =
57 assertAlmostEqual "c0012 is correct" (c t 0 0 1 2) (71/24)
58 where
59 g = make_grid 1 trilinear
60 cube = fromJust $ cube_at g 1 1 1
61 t = tetrahedron0 cube
62
63
64 -- | Check the value of c0120 for tetrahedron0 belonging to the
65 -- cube centered on (1,1,1) with a grid constructed from the
66 -- trilinear values. See example one in the paper.
67 test_trilinear_c0120 :: Assertion
68 test_trilinear_c0120 =
69 assertAlmostEqual "c0120 is correct" (c t 0 1 2 0) (55/24)
70 where
71 g = make_grid 1 trilinear
72 cube = fromJust $ cube_at g 1 1 1
73 t = tetrahedron0 cube
74
75
76 -- | Check the value of c0102 for tetrahedron0 belonging to the
77 -- cube centered on (1,1,1) with a grid constructed from the
78 -- trilinear values. See example one in the paper.
79 test_trilinear_c0102 :: Assertion
80 test_trilinear_c0102 =
81 assertAlmostEqual "c0102 is correct" (c t 0 1 0 2) (73/24)
82 where
83 g = make_grid 1 trilinear
84 cube = fromJust $ cube_at g 1 1 1
85 t = tetrahedron0 cube
86
87
88 -- | Check the value of c0111 for tetrahedron0 belonging to the
89 -- cube centered on (1,1,1) with a grid constructed from the
90 -- trilinear values. See example one in the paper.
91 test_trilinear_c0111 :: Assertion
92 test_trilinear_c0111 =
93 assertAlmostEqual "c0111 is correct" (c t 0 1 1 1) (8/3)
94 where
95 g = make_grid 1 trilinear
96 cube = fromJust $ cube_at g 1 1 1
97 t = tetrahedron0 cube
98
99
100 -- | Check the value of c0210 for tetrahedron0 belonging to the
101 -- cube centered on (1,1,1) with a grid constructed from the
102 -- trilinear values. See example one in the paper.
103 test_trilinear_c0210 :: Assertion
104 test_trilinear_c0210 =
105 assertAlmostEqual "c0210 is correct" (c t 0 2 1 0) (29/12)
106 where
107 g = make_grid 1 trilinear
108 cube = fromJust $ cube_at g 1 1 1
109 t = tetrahedron0 cube
110
111
112 -- | Check the value of c0201 for tetrahedron0 belonging to the
113 -- cube centered on (1,1,1) with a grid constructed from the
114 -- trilinear values. See example one in the paper.
115 test_trilinear_c0201 :: Assertion
116 test_trilinear_c0201 =
117 assertAlmostEqual "c0201 is correct" (c t 0 2 0 1) (11/4)
118 where
119 g = make_grid 1 trilinear
120 cube = fromJust $ cube_at g 1 1 1
121 t = tetrahedron0 cube
122
123
124 -- | Check the value of c0300 for tetrahedron0 belonging to the
125 -- cube centered on (1,1,1) with a grid constructed from the
126 -- trilinear values. See example one in the paper.
127 test_trilinear_c0300 :: Assertion
128 test_trilinear_c0300 =
129 assertAlmostEqual "c0300 is correct" (c t 0 3 0 0) (5/2)
130 where
131 g = make_grid 1 trilinear
132 cube = fromJust $ cube_at g 1 1 1
133 t = tetrahedron0 cube
134
135
136 -- | Check the value of c1020 for tetrahedron0 belonging to the
137 -- cube centered on (1,1,1) with a grid constructed from the
138 -- trilinear values. See example one in the paper.
139 test_trilinear_c1020 :: Assertion
140 test_trilinear_c1020 =
141 assertAlmostEqual "c1020 is correct" (c t 1 0 2 0) (8/3)
142 where
143 g = make_grid 1 trilinear
144 cube = fromJust $ cube_at g 1 1 1
145 t = tetrahedron0 cube
146
147
148 -- | Check the value of c1002 for tetrahedron0 belonging to the
149 -- cube centered on (1,1,1) with a grid constructed from the
150 -- trilinear values. See example one in the paper.
151 test_trilinear_c1002 :: Assertion
152 test_trilinear_c1002 =
153 assertAlmostEqual "c1002 is correct" (c t 1 0 0 2) (23/6)
154 where
155 g = make_grid 1 trilinear
156 cube = fromJust $ cube_at g 1 1 1
157 t = tetrahedron0 cube
158
159
160 -- | Check the value of c1011 for tetrahedron0 belonging to the
161 -- cube centered on (1,1,1) with a grid constructed from the
162 -- trilinear values. See example one in the paper.
163 test_trilinear_c1011 :: Assertion
164 test_trilinear_c1011 =
165 assertAlmostEqual "c1011 is correct" (c t 1 0 1 1) (13/4)
166 where
167 g = make_grid 1 trilinear
168 cube = fromJust $ cube_at g 1 1 1
169 t = tetrahedron0 cube
170
171
172 -- | Check the value of c1110 for tetrahedron0 belonging to the
173 -- cube centered on (1,1,1) with a grid constructed from the
174 -- trilinear values. See example one in the paper.
175 test_trilinear_c1110 :: Assertion
176 test_trilinear_c1110 =
177 assertAlmostEqual "c1110 is correct" (c t 1 1 1 0) (23/8)
178 where
179 g = make_grid 1 trilinear
180 cube = fromJust $ cube_at g 1 1 1
181 t = tetrahedron0 cube
182
183
184 -- | Check the value of c1101 for tetrahedron0 belonging to the
185 -- cube centered on (1,1,1) with a grid constructed from the
186 -- trilinear values. See example one in the paper.
187 test_trilinear_c1101 :: Assertion
188 test_trilinear_c1101 =
189 assertAlmostEqual "c1101 is correct" (c t 1 1 0 1) (27/8)
190 where
191 g = make_grid 1 trilinear
192 cube = fromJust $ cube_at g 1 1 1
193 t = tetrahedron0 cube
194
195
196 -- | Check the value of c1200 for tetrahedron0 belonging to the
197 -- cube centered on (1,1,1) with a grid constructed from the
198 -- trilinear values. See example one in the paper.
199 test_trilinear_c1200 :: Assertion
200 test_trilinear_c1200 =
201 assertAlmostEqual "c1200 is correct" (c t 1 2 0 0) 3
202 where
203 g = make_grid 1 trilinear
204 cube = fromJust $ cube_at g 1 1 1
205 t = tetrahedron0 cube
206
207
208 -- | Check the value of c2010 for tetrahedron0 belonging to the
209 -- cube centered on (1,1,1) with a grid constructed from the
210 -- trilinear values. See example one in the paper.
211 test_trilinear_c2010 :: Assertion
212 test_trilinear_c2010 =
213 assertAlmostEqual "c2010 is correct" (c t 2 0 1 0) (10/3)
214 where
215 g = make_grid 1 trilinear
216 cube = fromJust $ cube_at g 1 1 1
217 t = tetrahedron0 cube
218
219
220 -- | Check the value of c2001 for tetrahedron0 belonging to the
221 -- cube centered on (1,1,1) with a grid constructed from the
222 -- trilinear values. See example one in the paper.
223 test_trilinear_c2001 :: Assertion
224 test_trilinear_c2001 =
225 assertAlmostEqual "c2001 is correct" (c t 2 0 0 1) 4
226 where
227 g = make_grid 1 trilinear
228 cube = fromJust $ cube_at g 1 1 1
229 t = tetrahedron0 cube
230
231
232 -- | Check the value of c2100 for tetrahedron0 belonging to the
233 -- cube centered on (1,1,1) with a grid constructed from the
234 -- trilinear values. See example one in the paper.
235 test_trilinear_c2100 :: Assertion
236 test_trilinear_c2100 =
237 assertAlmostEqual "c2100 is correct" (c t 2 1 0 0) (7/2)
238 where
239 g = make_grid 1 trilinear
240 cube = fromJust $ cube_at g 1 1 1
241 t = tetrahedron0 cube
242
243
244 -- | Check the value of c3000 for tetrahedron0 belonging to the
245 -- cube centered on (1,1,1) with a grid constructed from the
246 -- trilinear values. See example one in the paper.
247 test_trilinear_c3000 :: Assertion
248 test_trilinear_c3000 =
249 assertAlmostEqual "c3000 is correct" (c t 3 0 0 0) 4
250 where
251 g = make_grid 1 trilinear
252 cube = fromJust $ cube_at g 1 1 1
253 t = tetrahedron0 cube
254
255
256 -- | Make sure that v0 of tetrahedron0 belonging to the cube centered
257 -- on (1,1,1) with a grid constructed from the trilinear values
258 -- winds up in the right place. See example one in the paper.
259 test_trilinear_f0_t0_v0 :: Assertion
260 test_trilinear_f0_t0_v0 =
261 assertEqual "v0 is correct" (v0 t) (1, 1, 1)
262 where
263 g = make_grid 1 trilinear
264 cube = fromJust $ cube_at g 1 1 1
265 t = tetrahedron0 cube
266
267
268 -- | Make sure that v1 of tetrahedron0 belonging to the cube centered
269 -- on (1,1,1) with a grid constructed from the trilinear values
270 -- winds up in the right place. See example one in the paper.
271 test_trilinear_f0_t0_v1 :: Assertion
272 test_trilinear_f0_t0_v1 =
273 assertEqual "v1 is correct" (v1 t) (0.5, 1, 1)
274 where
275 g = make_grid 1 trilinear
276 cube = fromJust $ cube_at g 1 1 1
277 t = tetrahedron0 cube
278
279
280 -- | Make sure that v2 of tetrahedron0 belonging to the cube centered
281 -- on (1,1,1) with a grid constructed from the trilinear values
282 -- winds up in the right place. See example one in the paper.
283 test_trilinear_f0_t0_v2 :: Assertion
284 test_trilinear_f0_t0_v2 =
285 assertEqual "v2 is correct" (v2 t) (0.5, 0.5, 1.5)
286 where
287 g = make_grid 1 trilinear
288 cube = fromJust $ cube_at g 1 1 1
289 t = tetrahedron0 cube
290
291
292 -- | Make sure that v3 of tetrahedron0 belonging to the cube centered
293 -- on (1,1,1) with a grid constructed from the trilinear values
294 -- winds up in the right place. See example one in the paper.
295 test_trilinear_f0_t0_v3 :: Assertion
296 test_trilinear_f0_t0_v3 =
297 assertClose "v3 is correct" (v3 t) (0.5, 1.5, 1.5)
298 where
299 g = make_grid 1 trilinear
300 cube = fromJust $ cube_at g 1 1 1
301 t = tetrahedron0 cube
302
303
304 test_trilinear_reproduced :: Assertion
305 test_trilinear_reproduced =
306 assertTrue "trilinears are reproduced correctly" $
307 and [p (i', j', k') ~= value_at trilinear i j k
308 | i <- [0..2],
309 j <- [0..2],
310 k <- [0..2],
311 t <- tetrahedra c0,
312 let p = polynomial t,
313 let i' = fromIntegral i,
314 let j' = fromIntegral j,
315 let k' = fromIntegral k]
316 where
317 g = make_grid 1 trilinear
318 c0 = fromJust $ cube_at g 1 1 1
319
320
321 test_zeros_reproduced :: Assertion
322 test_zeros_reproduced =
323 assertTrue "the zero function is reproduced correctly" $
324 and [p (i', j', k') ~= value_at zeros i j k
325 | i <- [0..2],
326 j <- [0..2],
327 k <- [0..2],
328 let i' = fromIntegral i,
329 let j' = fromIntegral j,
330 let k' = fromIntegral k]
331 where
332 g = make_grid 1 zeros
333 c0 = fromJust $ cube_at g 1 1 1
334 t0 = tetrahedron0 c0
335 p = polynomial t0
336
337
338 -- | Make sure we can reproduce a 9x9x9 trilinear from the 3x3x3 one.
339 test_trilinear9x9x9_reproduced :: Assertion
340 test_trilinear9x9x9_reproduced =
341 assertTrue "trilinear 9x9x9 is reproduced correctly" $
342 and [p (i', j', k') ~= value_at trilinear9x9x9 i j k
343 | i <- [0..8],
344 j <- [0..8],
345 k <- [0..8],
346 t <- tetrahedra c0,
347 let p = polynomial t,
348 let i' = (fromIntegral i) * 0.5,
349 let j' = (fromIntegral j) * 0.5,
350 let k' = (fromIntegral k) * 0.5]
351 where
352 g = make_grid 1 trilinear
353 c0 = fromJust $ cube_at g 1 1 1
354 t0 = tetrahedron0 c0
355 p = polynomial t0