Skip to content

Commit

Permalink
[ unfinished ] Add a relative weight distribution test
Browse files Browse the repository at this point in the history
  • Loading branch information
buzden committed Dec 10, 2024
1 parent e1cf449 commit c008088
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module DistrCheckCommon

import Data.List.Lazy

import public Test.DepTyCheck.Gen

import public Statistics.Norm.Precise
import public Statistics.Confidence

import System.Random.Pure.StdGen

%default total

find : LazyList (Vect n SignificantBounds) -> Maybe $ Vect n SignificantBounds
find [] = Nothing
find (x::xs) = case force xs of
[] => Just x
xs => if all isOk x then Just x else assert_total $ find xs

verdict : Vect n (CoverageTest a) -> Gen em a -> Maybe $ Vect n SignificantBounds
verdict conds = find . mapMaybe sequence .
checkCoverageConditions conds . unGenTryN 10000000 someStdGen

Show SignificantBounds where show = interpolate

export
printVerdict : HasIO m => Gen em a -> Vect n (CoverageTest a) -> m ()
printVerdict = putStrLn .: show .: flip verdict
6 changes: 6 additions & 0 deletions examples/sorted-tree-indexed/tests/gens/_common/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rm -rf build

flock "$1" pack -q install-deps test.ipkg && \
pack exec CheckDistribution.idr

rm -rf build
5 changes: 5 additions & 0 deletions examples/sorted-tree-indexed/tests/gens/_common/test.ipkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test

main = CheckDistribution

depends = deptycheck, summary-stat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module CheckDistribution

import Data.SortedBinTree.Gen

import Deriving.DepTyCheck.Gen

import DistrCheckCommon

%default total

%language ElabReflection

-- Check how weights of subtrees are related between left and right subtree of a root

mainFor : (depth : Nat) -> IO ()
mainFor depth = printVerdict (genSortedBinTree1 $ limit depth) $ fromList
$ [ coverWith (ratio 1 $ S depth) ((== n) . length) | n <- [0 .. depth] ]

main : IO ()
main = do
mainFor 0
mainFor 1
mainFor 2
mainFor 7
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Just [ok]
Just [ok, ok]
Just [ok, ok, ok]
Just [ok, ok, ok, ok, ok, ok, ok, ok]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test

main = CheckDistribution

depends = deptycheck, sorted-tree-indexed, summary-stat

0 comments on commit c008088

Please sign in to comment.