leancheck-0.9.2: Enumerative property-based testing

Copyright(c) 2017-2020 Rudy Matela
License3-Clause BSD (see the file LICENSE)
MaintainerRudy Matela <rudy@matela.com.br>
Safe HaskellSafe
LanguageHaskell2010

Test.LeanCheck.Stats

Description

This module is part of LeanCheck, a simple enumerative property-based testing library.

This module exports functions to compute statistics of Listable instances.

Synopsis

Documentation

classStats :: (Listable a, Show b) => Int -> (a -> b) -> IO () Source #

Prints statistics about a given Listable generator up to a number of test values.

For example, to know the distribution of the length of generated lists, just run:

> classStats 100 (length :: [Int] -> Int)
0:  1/100  1%
1:  6/100  6%
2: 16/100 16%
3: 25/100 25%
4: 26/100 26%
5: 18/100 18%
6:  7/100  7%
7:  1/100  1%

This provides similar functionality to QuickCheck's label, collect, classify and tabulate while keeping statistics separate from your properties.

classStatsT :: (Listable a, Show b) => Int -> (a -> b) -> IO () Source #

Same as classStats, but separated by tiers.

The first argument is the number of tiers to evaluate.

> classStatsT 6 (length :: [Int] -> Int)
      tot   0  1  2  3  4   5

tot:   32   1  1  2  4  8  16
  0:    1   1  0  0  0  0   0
  1:    5   0  1  1  1  1   1
  2:   10   0  0  1  2  3   4
  3:   10   0  0  0  1  3   6
  4:    5   0  0  0  0  1   4
  5:    1   0  0  0  0  0   1

Lines are values, columns are tiers:

> classStatsT 6 and
        tot   0  1  2  3   4   5

  tot:   63   1  2  4  8  16  32
 True:    6   1  1  1  1   1   1
False:   57   0  1  3  7  15  31

conditionStats :: Listable a => Int -> [(String, a -> Bool)] -> IO () Source #

How many values match each of a list of conditions?

How many odd and even numbers are in the Listable enumeration?

> conditionStats 1000 [("odd", odd :: Int -> Bool), ("even", even)]
 odd: 500/1000 50%
even: 500/1000 50%

How many of the generated lists are ordered?

> conditionStats 1000 [("ordered", ordered :: [Int] -> Bool)]
ordered: 131/1000 13%

conditionStatsT :: Listable a => Int -> [(String, a -> Bool)] -> IO () Source #

Same as conditionStats but by tier.

The first argument is the number of tiers to evaluate.

How many odd and even numbers are in each tier?

> conditionStatsT 10 [("odd", odd :: Int -> Bool), ("even", even)]
total: 1 1 1 1 1 1 1 1 1 1
  odd: 0 1 1 0 0 1 1 0 0 1
 even: 1 0 0 1 1 0 0 1 1 0

How many ordered lists are in each tier?

> conditionStatsT 10 [("ordered", ordered :: [Int] -> Bool)]
  total: 1 1 2 4 8 16 32 64 128 256
ordered: 1 1 2 3 5  7 11 15  22  30

classify :: Eq a => [a] -> [[a]] Source #

Classify values using their Eq instance.

> classify [1,2,3,1,2,1]
[[1,1,1],[2,2],[3]]

(cf. classifyBy, classifyOn)

classifyBy :: (a -> a -> Bool) -> [a] -> [[a]] Source #

Classify values by a given comparison function.

> classifyBy (\(x,_) (y,_) -> x == y) [(1,1),(1,2),(2,1),(2,2)]
[[(1,1),(1,2)],[(2,1),(2,2)]]

(cf. classify, classifyOn)

classifyOn :: Eq b => (a -> b) -> [a] -> [[a]] Source #

Classify values based on the result of a given function.

> classifyOn head ["sheep", "chip", "ship", "cheap"]
[["sheep","ship"],["chip","cheap"]]
> classifyOn odd [1,2,3,4,5,6]
[[1,3,5],[2,4,6]]

(cf. classify, classifyBy)

counts :: Eq a => [a] -> [(a, Int)] Source #

Returns the counts of each value in a list.

> counts "Mississippi"
[('M',1),('i',4),('s',4),('p',2)]

Values are returned in the order they appear.

countsBy :: (a -> a -> Bool) -> [a] -> [(a, Int)] Source #

Returns the counts of each value in a list using a given comparison function.

countsOn :: Eq b => (a -> b) -> [a] -> [(b, Int)] Source #

Returns the counts of each value in a list based on a projection.

> countsOn length ["sheep", "chip", "ship", "cheap", "Mississippi"]
[(5,2),(4,2),(11,1)]