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