Skip to content

Commit

Permalink
[ test, distr ] Add a relative weight distribution test
Browse files Browse the repository at this point in the history
  • Loading branch information
buzden committed Jan 27, 2025
1 parent 9e911f6 commit fe00a4d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/sorted-tree-indexed/src/Data/SortedBinTree.idr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ toList : SortedBinTree1 mi ma -> List Nat
toList (Leaf x) = [x]
toList (Node left right) = toList left ++ toList right

export
weight : SortedBinTree1 mi ma -> Nat
weight $ Leaf x = 1
weight $ Node l r = 1 + weight l + weight r

export
Interpolation (SortedBinTree1 mi ma) where
interpolate $ Leaf x = "\{show x}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module CheckDistribution

import Data.DPair
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

getLR : (mi ** ma ** SortedBinTree1 mi ma) -> Maybe $ let t = Exists $ Exists . SortedBinTree1 in (t, t)
getLR (_ ** _ ** Leaf {}) = Nothing
getLR (_ ** _ ** Node l r) = Just (Evidence _ $ Evidence _ l, Evidence _ $ Evidence _ r)

mainFor : (depth : Nat) -> IO ()
mainFor depth = printVerdict' getLR (genSortedBinTree1 $ limit depth) $ fromList
$ [ coverWith 1 (\(l, r) => weight l.snd.snd `f` weight r.snd.snd)
| (r, f) <-
[ (ratio 1 2, (>))
, (ratio 1 10, (==))
, (ratio 1 2, (<))
]
]

main : IO ()
main = do
mainFor 2
mainFor 4
mainFor 6
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Just [ok, ok, ok]
Just [ok, ok, ok]
Just [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 fe00a4d

Please sign in to comment.