approx-rand-test 0.1.0 → 0.1.1
raw patch · 2 files changed
+43/−26 lines, 2 filesdep +ieee754dep ~HUnitdep ~conduitdep ~mtlPVP ok
version bump matches the API change (PVP)
Dependencies added: ieee754
Dependency ranges changed: HUnit, conduit, mtl, text, transformers, vector
API changes (from Hackage documentation)
Files
- approx-rand-test.cabal +11/−10
- tests/tests.hs +32/−16
approx-rand-test.cabal view
@@ -1,5 +1,5 @@ Name: approx-rand-test-Version: 0.1.0+Version: 0.1.1 License: OtherLicense License-file: LICENSE Copyright: Copyright 2012 Daniël de Kok@@ -22,7 +22,7 @@ Source-Repository this Type: git Location: git://github.com/danieldk/approx-rand-test.git- Tag: 0.1.0+ Tag: 0.1.1 Flag withCairo Description: Enable non-terminal histogram output, requiring Cairo.@@ -35,8 +35,8 @@ Build-Depends: base >= 4 && < 5, vector >= 0.9 && < 0.11, mersenne-random-pure64 == 0.2.0.*, monad-mersenne-random == 0.1,- mtl == 2.1.*, statistics == 0.10.*,- transformers == 0.3.*+ mtl >= 2.0.1 && < 2.2, statistics == 0.10.*,+ transformers >= 0.2.2 && < 0.4 Executable approx_rand_test@@ -45,7 +45,7 @@ HS-Source-Dirs: utils Ghc-Options: -O2 -Wall Build-Depends: base >= 4 && < 5, approx-rand-test,- conduit >= 0.4 && < 0.6, text == 0.11.2.*,+ conduit >= 0.4 && < 1.1, text >= 0.11.1 && < 0.11.3, containers == 0.4.*, vector >= 0.9 && < 0.11, mersenne-random-pure64 == 0.2.0.*, monad-mersenne-random == 0.1,@@ -65,11 +65,11 @@ HS-Source-Dirs: utils Ghc-Options: -O2 -Wall Build-Depends: base >= 4 && < 5, approx-rand-test,- conduit >= 0.4 && < 0.6, text == 0.11.2.*,+ conduit >= 0.4 && < 1.1, text >= 0.11.1 && < 0.11.3, containers == 0.4.*, vector >= 0.9 && < 0.11, mersenne-random-pure64 == 0.2.0.*, monad-mersenne-random == 0.1,- mtl == 2.1.*, statistics == 0.10.*+ mtl >= 2.0.1 && < 2.2, statistics == 0.10.* if flag(withCairo) Hs-Source-Dirs: utils/cairo Build-Depends: Chart >= 0.15 && < 0.17, colour == 2.3.*,@@ -84,10 +84,11 @@ Hs-Source-Dirs: tests Main-Is: tests.hs ghc-options: -Wall- Build-Depends: base >= 4 && < 5, vector == 0.9.*,- approx-rand-test,+ Build-Depends: base >= 4 && < 5, vector >= 0.9 && < 0.11,+ approx-rand-test, mtl >= 2.0.1 && < 2.2,+ ieee754 == 0.7.*, mersenne-random-pure64 == 0.2.0.*, monad-mersenne-random == 0.1,- HUnit == 1.2.4.*,+ HUnit >= 1.2.4 && < 1.2.6, test-framework == 0.6.*, test-framework-hunit == 0.2.*
tests/tests.hs view
@@ -1,16 +1,18 @@ module Main where -import Control.Monad.Mersenne.Random (evalRandom)-import System.Random.Mersenne.Pure64 (pureMT)+import Control.Monad.Error (runErrorT)+import Control.Monad.Mersenne.Random (evalRandom)+import Numeric.IEEE (IEEE, epsilon)+import System.Random.Mersenne.Pure64 (pureMT) import qualified Data.Vector.Unboxed as V-import Statistics.Test.ApproxRand-import Test.HUnit (assertEqual)-import Test.Framework-import Test.Framework.Providers.HUnit+import Statistics.Test.ApproxRand+import Test.HUnit (Assertion, assertBool, assertEqual)+import Test.Framework+import Test.Framework.Providers.HUnit tests :: Test tests = testGroup "Paired approximate randomization tests" $- concat [statTests, randomizationTests]+ concat [statTests, randomizationTests] main :: IO () main = defaultMain [ tests ]@@ -22,8 +24,8 @@ meanDifferenceTest :: Test meanDifferenceTest =- testEquality "mean difference robot competition"- (meanDifference cohenRobotsAlpha cohenRobotsBeta) 1.8+ testIEEEEquality "mean difference robot competition"+ 1.8 $ meanDifference cohenRobotsAlpha cohenRobotsBeta -- Approximate andomization tests @@ -32,18 +34,32 @@ pairApproxExactTestScores :: Test pairApproxExactTestScores =- testEquality "number of extreme values robot competition"- (length $ filter (>= 1.8) scores) 21- where- scores = evalRandom- (approxRandPairScores meanDifference 1024- cohenRobotsAlpha cohenRobotsBeta) $- pureMT 42+ testEquality "number of extreme values robot competition"+ (Right 21) $ V.length `fmap` V.filter (>= 1.8) `fmap` scores+ where+ test = runErrorT $+ approxRandPairStats differenceMean 1024 cohenRobotsAlpha cohenRobotsBeta+ scores = evalRandom test $ pureMT 42 -- Helper functions testEquality :: (Show a, Eq a) => String -> a -> a -> Test testEquality msg a b = testCase msg $ assertEqual msg a b++testIEEEEquality :: IEEE a => String -> a -> a -> Test+testIEEEEquality msg a b = testCase msg $ assertEqualIEEE msg a b++assertEqualIEEE :: IEEE a => String -> a -> a -> Assertion+assertEqualIEEE msg a b = assertBool msg $ fracEq epsilon a b++-- Suggested in The Floating Point Guide: http://floating-point-gui.de/+fracEq :: (Fractional a, Ord a) => a -> a -> a -> Bool+fracEq eps a b+ | a == b = True+ | a * b == 0 = diff < (eps * eps)+ | otherwise = diff / (abs a + abs b) < eps+ where diff = abs (a - b)+ -- Example from Cohen, 1995 cohenRobotsAlpha :: V.Vector Double