Skip to content

Commit

Permalink
testing-utils: added set properties
Browse files Browse the repository at this point in the history
  • Loading branch information
coot committed May 7, 2024
1 parent 406f712 commit 44899a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ouroboros-network-testing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Non-Breaking changes

* Added `isSubsetProperty` and `disjoinSetsProperty` to `Ouroboros.Network.Testing.Utils`.

## 0.6.0.0 -- 2024-02-21

### Breaking changes
Expand Down
21 changes: 21 additions & 0 deletions ouroboros-network-testing/src/Ouroboros/Network/Testing/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module Ouroboros.Network.Testing.Utils
Delay (..)
, genDelayWithPrecision
, SmallDelay (..)
-- * Set properties
, isSubsetProperty
, disjointSetsProperty
-- * QuickCheck Utils
, arbitrarySubset
, shrinkVector
Expand Down Expand Up @@ -139,6 +142,24 @@ renderRanges r n = show lower ++ " -- " ++ show upper
lower = n - n `mod` r
upper = lower + (r-1)

--
-- Set properties
--

isSubsetProperty :: (Ord a, Show a) => String -> Set a -> Set a -> Property
isSubsetProperty name a b =
let d = a Set.\\ b
in counterexample
(name ++ "violates subset property: " ++ show d)
(Set.null d)

disjointSetsProperty :: (Ord a, Show a) => String -> Set a -> Set a -> Property
disjointSetsProperty name a b =
let d = a `Set.intersection` b
in counterexample
(name ++ "vaiolates disjoint set property: " ++ show d)
(Set.null d)

--
-- Tracing tools
--
Expand Down

0 comments on commit 44899a7

Please sign in to comment.