summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/tests/src/Numeric/GSL/Tests.hs41
-rw-r--r--packages/tests/src/Numeric/LinearAlgebra/Tests/Properties.hs5
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)
22import Numeric.LinearAlgebra.HMatrix 22import Numeric.LinearAlgebra.HMatrix
23import Numeric.GSL 23import Numeric.GSL
24import Numeric.LinearAlgebra.Tests (qCheck, utest) 24import Numeric.LinearAlgebra.Tests (qCheck, utest)
25import Numeric.LinearAlgebra.Tests.Properties ((|~|), (~~)) 25import 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
71interpolationTest = 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
71minimizationTest = TestList 109minimizationTest = 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
16module Numeric.LinearAlgebra.Tests.Properties ( 16module 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 (
45import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary) 45import Numeric.LinearAlgebra.HMatrix hiding (Testable,unitary)
46import Test.QuickCheck 46import Test.QuickCheck
47 47
48(~=) :: Double -> Double -> Bool
49a ~= b = abs (a - b) < 1e-10
50
48trivial :: Testable a => Bool -> a -> Property 51trivial :: Testable a => Bool -> a -> Property
49trivial = (`classify` "trivial") 52trivial = (`classify` "trivial")
50 53