]> gitweb.michael.orlitzky.com - spline3.git/blob - src/Tests/Cube.hs
666fde8899c168f85b061430ce06f5ee3ca93e1f
[spline3.git] / src / Tests / Cube.hs
1 module Tests.Cube
2 where
3
4 import Test.QuickCheck
5
6 import Comparisons
7 import Cube
8 import FunctionValues (FunctionValues)
9 import Tests.FunctionValues ()
10 import Tetrahedron (b0, b1, b2, b3, c,
11 Tetrahedron(Tetrahedron),
12 v0, v1, v2, v3, volume)
13
14 instance Arbitrary Cube where
15 arbitrary = do
16 (Positive h') <- arbitrary :: Gen (Positive Double)
17 i' <- choose (coordmin, coordmax)
18 j' <- choose (coordmin, coordmax)
19 k' <- choose (coordmin, coordmax)
20 fv' <- arbitrary :: Gen FunctionValues
21 return (Cube h' i' j' k' fv')
22 where
23 coordmin = -268435456 -- -(2^29 / 2)
24 coordmax = 268435456 -- +(2^29 / 2)
25
26
27 -- Quickcheck tests.
28
29 -- | Since the grid size is necessarily positive, all tetrahedrons
30 -- (which comprise cubes of positive volume) must have positive volume
31 -- as well.
32 prop_all_volumes_positive :: Cube -> Bool
33 prop_all_volumes_positive c =
34 null nonpositive_volumes
35 where
36 ts = tetrahedrons c
37 volumes = map volume ts
38 nonpositive_volumes = filter (<= 0) volumes
39
40 -- | In fact, since all of the tetrahedra are identical, we should
41 -- already know their volumes. There's 24 tetrahedra to a cube, so
42 -- we'd expect the volume of each one to be (1/24)*h^3.
43 prop_tetrahedron0_volumes_exact :: Cube -> Bool
44 prop_tetrahedron0_volumes_exact c =
45 volume (tetrahedron0 c) ~= (1/24)*(delta^(3::Int))
46 where
47 delta = h c
48
49 -- | In fact, since all of the tetrahedra are identical, we should
50 -- already know their volumes. There's 24 tetrahedra to a cube, so
51 -- we'd expect the volume of each one to be (1/24)*h^3.
52 prop_tetrahedron1_volumes_exact :: Cube -> Bool
53 prop_tetrahedron1_volumes_exact c =
54 volume (tetrahedron1 c) ~= (1/24)*(delta^(3::Int))
55 where
56 delta = h c
57
58 -- | In fact, since all of the tetrahedra are identical, we should
59 -- already know their volumes. There's 24 tetrahedra to a cube, so
60 -- we'd expect the volume of each one to be (1/24)*h^3.
61 prop_tetrahedron2_volumes_exact :: Cube -> Bool
62 prop_tetrahedron2_volumes_exact c =
63 volume (tetrahedron2 c) ~= (1/24)*(delta^(3::Int))
64 where
65 delta = h c
66
67 -- | In fact, since all of the tetrahedra are identical, we should
68 -- already know their volumes. There's 24 tetrahedra to a cube, so
69 -- we'd expect the volume of each one to be (1/24)*h^3.
70 prop_tetrahedron3_volumes_exact :: Cube -> Bool
71 prop_tetrahedron3_volumes_exact c =
72 volume (tetrahedron3 c) ~= (1/24)*(delta^(3::Int))
73 where
74 delta = h c
75
76 -- | In fact, since all of the tetrahedra are identical, we should
77 -- already know their volumes. There's 24 tetrahedra to a cube, so
78 -- we'd expect the volume of each one to be (1/24)*h^3.
79 prop_tetrahedron4_volumes_exact :: Cube -> Bool
80 prop_tetrahedron4_volumes_exact c =
81 volume (tetrahedron4 c) ~= (1/24)*(delta^(3::Int))
82 where
83 delta = h c
84
85 -- | In fact, since all of the tetrahedra are identical, we should
86 -- already know their volumes. There's 24 tetrahedra to a cube, so
87 -- we'd expect the volume of each one to be (1/24)*h^3.
88 prop_tetrahedron5_volumes_exact :: Cube -> Bool
89 prop_tetrahedron5_volumes_exact c =
90 volume (tetrahedron5 c) ~= (1/24)*(delta^(3::Int))
91 where
92 delta = h c
93
94 -- | In fact, since all of the tetrahedra are identical, we should
95 -- already know their volumes. There's 24 tetrahedra to a cube, so
96 -- we'd expect the volume of each one to be (1/24)*h^3.
97 prop_tetrahedron6_volumes_exact :: Cube -> Bool
98 prop_tetrahedron6_volumes_exact c =
99 volume (tetrahedron6 c) ~= (1/24)*(delta^(3::Int))
100 where
101 delta = h c
102
103 -- | In fact, since all of the tetrahedra are identical, we should
104 -- already know their volumes. There's 24 tetrahedra to a cube, so
105 -- we'd expect the volume of each one to be (1/24)*h^3.
106 prop_tetrahedron7_volumes_exact :: Cube -> Bool
107 prop_tetrahedron7_volumes_exact c =
108 volume (tetrahedron7 c) ~= (1/24)*(delta^(3::Int))
109 where
110 delta = h c
111
112 -- | All tetrahedron should have their v0 located at the center of the cube.
113 prop_v0_all_equal :: Cube -> Bool
114 prop_v0_all_equal c = (v0 t0) == (v0 t1)
115 where
116 t0 = head (tetrahedrons c) -- Doesn't matter which two we choose.
117 t1 = head $ tail (tetrahedrons c)
118
119
120 -- | This pretty much repeats the prop_all_volumes_positive property,
121 -- but will let me know which tetrahedrons's vertices are disoriented.
122 prop_tetrahedron0_volumes_positive :: Cube -> Bool
123 prop_tetrahedron0_volumes_positive c =
124 volume (tetrahedron0 c) > 0
125
126 -- | This pretty much repeats the prop_all_volumes_positive property,
127 -- but will let me know which tetrahedrons's vertices are disoriented.
128 prop_tetrahedron1_volumes_positive :: Cube -> Bool
129 prop_tetrahedron1_volumes_positive c =
130 volume (tetrahedron1 c) > 0
131
132 -- | This pretty much repeats the prop_all_volumes_positive property,
133 -- but will let me know which tetrahedrons's vertices are disoriented.
134 prop_tetrahedron2_volumes_positive :: Cube -> Bool
135 prop_tetrahedron2_volumes_positive c =
136 volume (tetrahedron2 c) > 0
137
138 -- | This pretty much repeats the prop_all_volumes_positive property,
139 -- but will let me know which tetrahedrons's vertices are disoriented.
140 prop_tetrahedron3_volumes_positive :: Cube -> Bool
141 prop_tetrahedron3_volumes_positive c =
142 volume (tetrahedron3 c) > 0
143
144 -- | This pretty much repeats the prop_all_volumes_positive property,
145 -- but will let me know which tetrahedrons's vertices are disoriented.
146 prop_tetrahedron4_volumes_positive :: Cube -> Bool
147 prop_tetrahedron4_volumes_positive c =
148 volume (tetrahedron4 c) > 0
149
150 -- | This pretty much repeats the prop_all_volumes_positive property,
151 -- but will let me know which tetrahedrons's vertices are disoriented.
152 prop_tetrahedron5_volumes_positive :: Cube -> Bool
153 prop_tetrahedron5_volumes_positive c =
154 volume (tetrahedron5 c) > 0
155
156 -- | This pretty much repeats the prop_all_volumes_positive property,
157 -- but will let me know which tetrahedrons's vertices are disoriented.
158 prop_tetrahedron6_volumes_positive :: Cube -> Bool
159 prop_tetrahedron6_volumes_positive c =
160 volume (tetrahedron6 c) > 0
161
162 -- | This pretty much repeats the prop_all_volumes_positive property,
163 -- but will let me know which tetrahedrons's vertices are disoriented.
164 prop_tetrahedron7_volumes_positive :: Cube -> Bool
165 prop_tetrahedron7_volumes_positive c =
166 volume (tetrahedron7 c) > 0
167
168 -- | This pretty much repeats the prop_all_volumes_positive property,
169 -- but will let me know which tetrahedrons's vertices are disoriented.
170 prop_tetrahedron8_volumes_positive :: Cube -> Bool
171 prop_tetrahedron8_volumes_positive c =
172 volume (tetrahedron8 c) > 0
173
174 -- | This pretty much repeats the prop_all_volumes_positive property,
175 -- but will let me know which tetrahedrons's vertices are disoriented.
176 prop_tetrahedron9_volumes_positive :: Cube -> Bool
177 prop_tetrahedron9_volumes_positive c =
178 volume (tetrahedron9 c) > 0
179
180 -- | This pretty much repeats the prop_all_volumes_positive property,
181 -- but will let me know which tetrahedrons's vertices are disoriented.
182 prop_tetrahedron10_volumes_positive :: Cube -> Bool
183 prop_tetrahedron10_volumes_positive c =
184 volume (tetrahedron10 c) > 0
185
186 -- | This pretty much repeats the prop_all_volumes_positive property,
187 -- but will let me know which tetrahedrons's vertices are disoriented.
188 prop_tetrahedron11_volumes_positive :: Cube -> Bool
189 prop_tetrahedron11_volumes_positive c =
190 volume (tetrahedron11 c) > 0
191
192 -- | This pretty much repeats the prop_all_volumes_positive property,
193 -- but will let me know which tetrahedrons's vertices are disoriented.
194 prop_tetrahedron12_volumes_positive :: Cube -> Bool
195 prop_tetrahedron12_volumes_positive c =
196 volume (tetrahedron12 c) > 0
197
198 -- | This pretty much repeats the prop_all_volumes_positive property,
199 -- but will let me know which tetrahedrons's vertices are disoriented.
200 prop_tetrahedron13_volumes_positive :: Cube -> Bool
201 prop_tetrahedron13_volumes_positive c =
202 volume (tetrahedron13 c) > 0
203
204 -- | This pretty much repeats the prop_all_volumes_positive property,
205 -- but will let me know which tetrahedrons's vertices are disoriented.
206 prop_tetrahedron14_volumes_positive :: Cube -> Bool
207 prop_tetrahedron14_volumes_positive c =
208 volume (tetrahedron14 c) > 0
209
210 -- | This pretty much repeats the prop_all_volumes_positive property,
211 -- but will let me know which tetrahedrons's vertices are disoriented.
212 prop_tetrahedron15_volumes_positive :: Cube -> Bool
213 prop_tetrahedron15_volumes_positive c =
214 volume (tetrahedron15 c) > 0
215
216 -- | This pretty much repeats the prop_all_volumes_positive property,
217 -- but will let me know which tetrahedrons's vertices are disoriented.
218 prop_tetrahedron16_volumes_positive :: Cube -> Bool
219 prop_tetrahedron16_volumes_positive c =
220 volume (tetrahedron16 c) > 0
221
222 -- | This pretty much repeats the prop_all_volumes_positive property,
223 -- but will let me know which tetrahedrons's vertices are disoriented.
224 prop_tetrahedron17_volumes_positive :: Cube -> Bool
225 prop_tetrahedron17_volumes_positive c =
226 volume (tetrahedron17 c) > 0
227
228 -- | This pretty much repeats the prop_all_volumes_positive property,
229 -- but will let me know which tetrahedrons's vertices are disoriented.
230 prop_tetrahedron18_volumes_positive :: Cube -> Bool
231 prop_tetrahedron18_volumes_positive c =
232 volume (tetrahedron18 c) > 0
233
234 -- | This pretty much repeats the prop_all_volumes_positive property,
235 -- but will let me know which tetrahedrons's vertices are disoriented.
236 prop_tetrahedron19_volumes_positive :: Cube -> Bool
237 prop_tetrahedron19_volumes_positive c =
238 volume (tetrahedron19 c) > 0
239
240 -- | This pretty much repeats the prop_all_volumes_positive property,
241 -- but will let me know which tetrahedrons's vertices are disoriented.
242 prop_tetrahedron20_volumes_positive :: Cube -> Bool
243 prop_tetrahedron20_volumes_positive c =
244 volume (tetrahedron20 c) > 0
245
246 -- | This pretty much repeats the prop_all_volumes_positive property,
247 -- but will let me know which tetrahedrons's vertices are disoriented.
248 prop_tetrahedron21_volumes_positive :: Cube -> Bool
249 prop_tetrahedron21_volumes_positive c =
250 volume (tetrahedron21 c) > 0
251
252 -- | This pretty much repeats the prop_all_volumes_positive property,
253 -- but will let me know which tetrahedrons's vertices are disoriented.
254 prop_tetrahedron22_volumes_positive :: Cube -> Bool
255 prop_tetrahedron22_volumes_positive c =
256 volume (tetrahedron22 c) > 0
257
258 -- | This pretty much repeats the prop_all_volumes_positive property,
259 -- but will let me know which tetrahedrons's vertices are disoriented.
260 prop_tetrahedron23_volumes_positive :: Cube -> Bool
261 prop_tetrahedron23_volumes_positive c =
262 volume (tetrahedron23 c) > 0
263
264
265 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
266 -- fourth indices of c-t3 have been switched. This is because we
267 -- store the triangles oriented such that their volume is
268 -- positive. If T and T-tilde share <v0,v1,v2> and v3,v3-tilde point
269 -- in opposite directions, one of them has to have negative volume!
270 prop_c0120_identity1 :: Cube -> Bool
271 prop_c0120_identity1 cube =
272 c t0 0 1 2 0 ~= (c t0 0 0 2 1 + c t3 0 0 1 2) / 2
273 where
274 t0 = tetrahedron0 cube
275 t3 = tetrahedron3 cube
276
277
278 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
279 -- fourth indices of c-t3 have been switched. This is because we
280 -- store the triangles oriented such that their volume is
281 -- positive. If T and T-tilde share <v0,v1,v2> and v3,v3-tilde point
282 -- in opposite directions, one of them has to have negative volume!
283 prop_c0210_identity1 :: Cube -> Bool
284 prop_c0210_identity1 cube =
285 c t0 0 2 1 0 ~= (c t0 0 1 1 1 + c t3 0 1 1 1) / 2
286 where
287 t0 = tetrahedron0 cube
288 t3 = tetrahedron3 cube
289
290
291 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
292 -- fourth indices of c-t3 have been switched. This is because we
293 -- store the triangles oriented such that their volume is
294 -- positive. If T and T-tilde share <v0,v1,v2> and v3,v3-tilde point
295 -- in opposite directions, one of them has to have negative volume!
296 prop_c0300_identity1 :: Cube -> Bool
297 prop_c0300_identity1 cube =
298 c t0 0 3 0 0 ~= (c t0 0 2 0 1 + c t3 0 2 1 0) / 2
299 where
300 t0 = tetrahedron0 cube
301 t3 = tetrahedron3 cube
302
303
304 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
305 -- fourth indices of c-t3 have been switched. This is because we
306 -- store the triangles oriented such that their volume is
307 -- positive. If T and T-tilde share <v0,v1,v2> and v3,v3-tilde point
308 -- in opposite directions, one of them has to have negative volume!
309 prop_c1110_identity :: Cube -> Bool
310 prop_c1110_identity cube =
311 c t0 1 1 1 0 ~= (c t0 1 0 1 1 + c t3 1 0 1 1) / 2
312 where
313 t0 = tetrahedron0 cube
314 t3 = tetrahedron3 cube
315
316
317 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
318 -- fourth indices of c-t3 have been switched. This is because we
319 -- store the triangles oriented such that their volume is
320 -- positive. If T and T-tilde share <v0,v1,v2> and v3,v3-tilde point
321 -- in opposite directions, one of them has to have negative volume!
322 prop_c1200_identity1 :: Cube -> Bool
323 prop_c1200_identity1 cube =
324 c t0 1 2 0 0 ~= (c t0 1 1 0 1 + c t3 1 1 1 0) / 2
325 where
326 t0 = tetrahedron0 cube
327 t3 = tetrahedron3 cube
328
329
330 -- | Given in Sorokina and Zeilfelder, p. 79. Note that the third and
331 -- fourth indices of c-t3 have been switched. This is because we
332 -- store the triangles oriented such that their volume is
333 -- positive. If T and T-tilde share <v0,v1,v2> and v3,v3-tilde point
334 -- in opposite directions, one of them has to have negative volume!
335 prop_c2100_identity1 :: Cube -> Bool
336 prop_c2100_identity1 cube =
337 c t0 2 1 0 0 ~= (c t0 2 0 0 1 + c t3 2 0 1 0) / 2
338 where
339 t0 = tetrahedron0 cube
340 t3 = tetrahedron3 cube
341
342
343
344 -- | Given in Sorokina and Zeilfelder, p. 78.
345 -- prop_cijk1_identity :: Cube -> Bool
346 -- prop_cijk1_identity cube =
347 -- and [ c t0 i j k 1 ~=
348 -- (c t1 (i+1) j k 0) * ((b0 t0) (v3 t1)) +
349 -- (c t1 i (j+1) k 0) * ((b1 t0) (v3 t1)) +
350 -- (c t1 i j (k+1) 0) * ((b2 t0) (v3 t1)) +
351 -- (c t1 i j k 1) * ((b3 t0) (v3 t1)) | i <- [0..2],
352 -- j <- [0..2],
353 -- k <- [0..2],
354 -- i + j + k == 2]
355 -- where
356 -- t0 = tetrahedron0 cube
357 -- t1 = tetrahedron1 cube