Commit 6bb77749 authored by Klaus Aehlig's avatar Klaus Aehlig

Verify the update of the standard deviation statistics

Add a test that verifies that the error introduced by updating
a standard-deviation statistics of a sample with at least two
elements is not too large, as compared to the direct computation.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 394a5cb9
......@@ -318,6 +318,23 @@ prop_splitRecombineEithers es =
(splitleft, splitright, trail) = splitEithers es
emptylist = []::[Int]
-- | Test the update function for standard deviations against the naive
-- implementation.
prop_stddev_update :: Property
prop_stddev_update =
forAll (choose (0, 6) >>= flip vectorOf (choose (0, 1))) $ \xs ->
forAll (choose (0, 1)) $ \a ->
forAll (choose (0, 1)) $ \b ->
forAll (choose (1, 6) >>= flip vectorOf (choose (0, 1))) $ \ys ->
let original = xs ++ [a] ++ ys
modified = xs ++ [b] ++ ys
with_update = getStatisticValue
$ updateStatistics (getStdDevStatistics original) (a,b)
direct = stdDev modified
in printTestCase ("Value computed by update " ++ show with_update
++ " differs too much from correct value " ++ show direct)
(abs (with_update - direct) < 1e-12)
-- | Test list for the Utils module.
testSuite "Utils"
[ 'prop_commaJoinSplit
......@@ -344,4 +361,5 @@ testSuite "Utils"
, 'prop_chompPrefix_empty_string
, 'prop_chompPrefix_nothing
, 'prop_splitRecombineEithers
, 'prop_stddev_update
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment