diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tests.hs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/examples/tests.hs b/examples/tests.hs index 3b1d878..22c4674 100644 --- a/examples/tests.hs +++ b/examples/tests.hs | |||
@@ -12,11 +12,14 @@ import GSL.Vector | |||
12 | import GSL.Integration | 12 | import GSL.Integration |
13 | import GSL.Differentiation | 13 | import GSL.Differentiation |
14 | import GSL.Special | 14 | import GSL.Special |
15 | import GSL.Fourier | ||
16 | import GSL.Polynomials | ||
15 | import LAPACK | 17 | import LAPACK |
16 | import Test.QuickCheck | 18 | import Test.QuickCheck |
17 | import Test.HUnit | 19 | import Test.HUnit |
18 | import Complex | 20 | import Complex |
19 | 21 | ||
22 | |||
20 | {- | 23 | {- |
21 | -- Bravo por quickCheck! | 24 | -- Bravo por quickCheck! |
22 | 25 | ||
@@ -244,6 +247,29 @@ pinvSVDR m = linearSolveSVDR Nothing m (ident (rows m)) | |||
244 | 247 | ||
245 | pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m)) | 248 | pinvSVDC m = linearSolveSVDC Nothing m (ident (rows m)) |
246 | 249 | ||
250 | -------------------------------------------------------------------- | ||
251 | |||
252 | polyEval cs x = foldr (\c ac->ac*x+c) 0 cs | ||
253 | |||
254 | polySolveTest' p = length p <2 || last p == 0|| 1E-8 > maximum (map magnitude $ map (polyEval (map (:+0) p)) (polySolve p)) | ||
255 | where l1 |~~| l2 = eps > aproxL magnitude l1 l2 | ||
256 | |||
257 | polySolveTest = assertBool "polySolve" (polySolveTest' [1,2,3,4]) | ||
258 | |||
259 | --------------------------------------------------------------------- | ||
260 | |||
261 | quad f a b = fst $ integrateQAGS 1E-9 100 f a b | ||
262 | |||
263 | -- A multiple integral can be easily defined using partial application | ||
264 | quad2 f a b g1 g2 = quad h a b | ||
265 | where h x = quad (f x) (g1 x) (g2 x) | ||
266 | |||
267 | volSphere r = 8 * quad2 (\x y -> sqrt (r*r-x*x-y*y)) | ||
268 | 0 r (const 0) (\x->sqrt (r*r-x*x)) | ||
269 | |||
270 | integrateTest = assertBool "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5^3) < eps) | ||
271 | |||
272 | |||
247 | --------------------------------------------------------------------- | 273 | --------------------------------------------------------------------- |
248 | 274 | ||
249 | arit1 u = vectorMapValR PowVS 2 (vectorMapR Sin u) | 275 | arit1 u = vectorMapValR PowVS 2 (vectorMapR Sin u) |
@@ -271,6 +297,8 @@ exponentialTest = do | |||
271 | tests = TestList | 297 | tests = TestList |
272 | [ TestCase $ besselTest | 298 | [ TestCase $ besselTest |
273 | , TestCase $ exponentialTest | 299 | , TestCase $ exponentialTest |
300 | , TestCase $ polySolveTest | ||
301 | , TestCase $ integrateTest | ||
274 | ] | 302 | ] |
275 | 303 | ||
276 | ---------------------------------------------------------------------- | 304 | ---------------------------------------------------------------------- |
@@ -315,9 +343,12 @@ main = do | |||
315 | quickCheck arit2 | 343 | quickCheck arit2 |
316 | putStrLn "--------- GSL ------" | 344 | putStrLn "--------- GSL ------" |
317 | runTestTT tests | 345 | runTestTT tests |
346 | quickCheck $ \v -> ifft (fft v) ~~ v | ||
318 | 347 | ||
319 | kk = (2><2) | 348 | kk = (2><2) |
320 | [ 1.0, 0.0 | 349 | [ 1.0, 0.0 |
321 | , -1.5, 1.0 ::Double] | 350 | , -1.5, 1.0 ::Double] |
322 | 351 | ||
323 | v = 11 # [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0::Double] \ No newline at end of file | 352 | v = 11 # [0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0::Double] |
353 | |||
354 | pol = [14.125,-7.666666666666667,-14.3,-13.0,-7.0,-9.6,4.666666666666666,13.0,0.5] \ No newline at end of file | ||