From 505879855c6fa83b81ab31b57daaf8034634a19e Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sun, 7 Sep 2014 12:04:03 +0200 Subject: fix min/maxIndex bug, add tests, thanks --- packages/tests/hmatrix-tests.cabal | 2 +- packages/tests/src/Numeric/LinearAlgebra/Tests.hs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'packages/tests') diff --git a/packages/tests/hmatrix-tests.cabal b/packages/tests/hmatrix-tests.cabal index a417096..0514843 100644 --- a/packages/tests/hmatrix-tests.cabal +++ b/packages/tests/hmatrix-tests.cabal @@ -1,5 +1,5 @@ Name: hmatrix-tests -Version: 0.4.0.1 +Version: 0.4.1.0 License: BSD3 License-file: LICENSE Author: Alberto Ruiz diff --git a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs index 841b0d8..8587561 100644 --- a/packages/tests/src/Numeric/LinearAlgebra/Tests.hs +++ b/packages/tests/src/Numeric/LinearAlgebra/Tests.hs @@ -398,12 +398,33 @@ staticTest = utest "static" (fst $ checkT (undefined :: L 3 5)) -------------------------------------------------------------------------------- +indexProp g f x = a1 == g a2 && a2 == a3 && b1 == g b2 && b2 == b3 + where + l = map g (toList (f x)) + a1 = maximum l + b1 = minimum l + a2 = x `atIndex` maxIndex x + b2 = x `atIndex` minIndex x + a3 = maxElement x + b3 = minElement x + +-------------------------------------------------------------------------------- + -- | All tests must pass with a maximum dimension of about 20 -- (some tests may fail with bigger sizes due to precision loss). runTests :: Int -- ^ maximum dimension -> IO () runTests n = do let test p = qCheck n p + putStrLn "------ index" + test( \m -> indexProp id flatten (single (m :: RM)) ) + test( \v -> indexProp id id (single (v :: Vector Double)) ) + test( \m -> indexProp id flatten (m :: RM) ) + test( \v -> indexProp id id (v :: Vector Double) ) + test( \m -> indexProp magnitude flatten (single (m :: CM)) ) + test( \v -> indexProp magnitude id (single (v :: Vector (Complex Double))) ) + test( \m -> indexProp magnitude flatten (m :: CM) ) + test( \v -> indexProp magnitude id (v :: Vector (Complex Double)) ) putStrLn "------ mult Double" test (multProp1 10 . rConsist) test (multProp1 10 . cConsist) -- cgit v1.2.3