diff options
author | Matthew Peddie <mpeddie@gmail.com> | 2015-07-22 20:42:38 +1000 |
---|---|---|
committer | Matthew Peddie <mpeddie@gmail.com> | 2015-07-22 20:42:38 +1000 |
commit | f6a23683ae87810b8673c069eda4a8c0958ce84f (patch) | |
tree | 10120608a8f14a1138c9590d212ef8bcb09272b4 /packages | |
parent | f4de670a45b193edb45c4689310271f10f52b205 (diff) |
Add unit tests for GSL interpolation module
Diffstat (limited to 'packages')
-rw-r--r-- | packages/tests/src/Numeric/GSL/Tests.hs | 41 | ||||
-rw-r--r-- | packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs | 5 |
2 files changed, 44 insertions, 2 deletions
diff --git a/packages/tests/src/Numeric/GSL/Tests.hs b/packages/tests/src/Numeric/GSL/Tests.hs index e5d205d..3065fd8 100644 --- a/packages/tests/src/Numeric/GSL/Tests.hs +++ b/packages/tests/src/Numeric/GSL/Tests.hs | |||
@@ -22,7 +22,7 @@ import Test.HUnit (runTestTT, failures, Test(..), errors) | |||
22 | import Numeric.LinearAlgebra.HMatrix | 22 | import Numeric.LinearAlgebra.HMatrix |
23 | import Numeric.GSL | 23 | import Numeric.GSL |
24 | import Numeric.LinearAlgebra.Tests (qCheck, utest) | 24 | import Numeric.LinearAlgebra.Tests (qCheck, utest) |
25 | import Numeric.LinearAlgebra.Tests.Properties ((|~|), (~~)) | 25 | import Numeric.LinearAlgebra.Tests.Properties ((|~|), (~~), (~=)) |
26 | 26 | ||
27 | --------------------------------------------------------------------- | 27 | --------------------------------------------------------------------- |
28 | 28 | ||
@@ -66,6 +66,44 @@ rootFindingTest = TestList [ utest "root Hybrids" (fst sol1 ~~ [1,1]) | |||
66 | jacobian a b [x,_y] = [ [-a , 0] | 66 | jacobian a b [x,_y] = [ [-a , 0] |
67 | , [-2*b*x, b] ] | 67 | , [-2*b*x, b] ] |
68 | 68 | ||
69 | -------------------------------------------------------------------- | ||
70 | |||
71 | interpolationTest = TestList [ | ||
72 | utest "interpolation evaluateV" (esol ~= ev) | ||
73 | , utest "interpolation evaluate" (esol ~= eval) | ||
74 | , utest "interpolation evaluateDerivativeV" (desol ~= dev) | ||
75 | , utest "interpolation evaluateDerivative" (desol ~= de) | ||
76 | , utest "interpolation evaluateDerivative2V" (d2esol ~= d2ev) | ||
77 | , utest "interpolation evaluateDerivative2" (d2esol ~= d2e) | ||
78 | , utest "interpolation evaluateIntegralV" (intesol ~= intev) | ||
79 | , utest "interpolation evaluateIntegral" (intesol ~= inte) | ||
80 | ] | ||
81 | where | ||
82 | xtest = 2.2 | ||
83 | applyVec f = f Akima xs ys xtest | ||
84 | applyList f = f Akima (zip xs' ys') xtest | ||
85 | |||
86 | esol = xtest**2 | ||
87 | ev = applyVec evaluateV | ||
88 | eval = applyList evaluate | ||
89 | |||
90 | desol = 2*xtest | ||
91 | dev = applyVec evaluateDerivativeV | ||
92 | de = applyList evaluateDerivative | ||
93 | |||
94 | d2esol = 2 | ||
95 | d2ev = applyVec evaluateDerivative2V | ||
96 | d2e = applyList evaluateDerivative2 | ||
97 | |||
98 | intesol = 1/3 * xtest**3 | ||
99 | intev = evaluateIntegralV Akima xs ys 0 xtest | ||
100 | inte = evaluateIntegral Akima (zip xs' ys') (0, xtest) | ||
101 | |||
102 | xs' = [-1..10] | ||
103 | ys' = map (**2) xs' | ||
104 | xs = vector xs' | ||
105 | ys = vector ys' | ||
106 | |||
69 | --------------------------------------------------------------------- | 107 | --------------------------------------------------------------------- |
70 | 108 | ||
71 | minimizationTest = TestList | 109 | minimizationTest = TestList |
@@ -123,6 +161,7 @@ runTests n = do | |||
123 | , odeTest | 161 | , odeTest |
124 | , rootFindingTest | 162 | , rootFindingTest |
125 | , minimizationTest | 163 | , minimizationTest |
164 | , interpolationTest | ||
126 | , utest "deriv" derivTest | 165 | , utest "deriv" derivTest |
127 | , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5**3) < 1E-8) | 166 | , utest "integrate" (abs (volSphere 2.5 - 4/3*pi*2.5**3) < 1E-8) |
128 | , utest "polySolve" (polySolveProp [1,2,3,4]) | 167 | , utest "polySolve" (polySolveProp [1,2,3,4]) |
diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs index 720b7bd..046644f 100644 --- a/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs | |||
@@ -14,7 +14,7 @@ Testing properties. | |||
14 | -} | 14 | -} |
15 | 15 | ||
16 | module Numeric.LinearAlgebra.Tests.Properties ( | 16 | module Numeric.LinearAlgebra.Tests.Properties ( |
17 | dist, (|~|), (~~), (~:), Aprox((:~)), | 17 | dist, (|~|), (~~), (~:), Aprox((:~)), (~=), |
18 | zeros, ones, | 18 | zeros, ones, |
19 | square, | 19 | square, |
20 | unitary, | 20 | unitary, |
@@ -45,6 +45,9 @@ module Numeric.LinearAlgebra.Tests.Properties ( | |||
45 | import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary) | 45 | import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary) |
46 | import Test.QuickCheck | 46 | import Test.QuickCheck |
47 | 47 | ||
48 | (~=) :: Double -> Double -> Bool | ||
49 | a ~= b = abs (a - b) < 1e-10 | ||
50 | |||
48 | trivial :: Testable a => Bool -> a -> Property | 51 | trivial :: Testable a => Bool -> a -> Property |
49 | trivial = (`classify` "trivial") | 52 | trivial = (`classify` "trivial") |
50 | 53 | ||