[Exported pair, and added two related helper functions. Nils Anders Danielsson **20050531203756] { hunk ./Test/ChasingBottoms/TestUtilities.hs 22 + -- * Helper functions + , pair + , triple + , pair3 hunk ./Test/ChasingBottoms/TestUtilities.hs 36 +import Control.Arrow +import Control.Monad hunk ./Test/ChasingBottoms/TestUtilities.hs 386 --- Local helper functions +-- Helper functions hunk ./Test/ChasingBottoms/TestUtilities.hs 397 +-- | 'triple' works like 'pair', but for triples. + +triple :: Gen a -> (a -> Gen b) -> (b -> Gen c) -> Gen (a, b, c) +triple gen1 gen2 gen3 = do + x <- gen1 + y <- gen2 x + z <- gen3 y + return (x, y, z) + +-- | Given two generators, where the second one depends on elements +-- generated by the first one, 'pair3' generates three kinds of pairs: +-- +-- 1. Containing two elements from the first generator. +-- +-- 2. Containing one element from the first and one from the second. +-- +-- 3. Containing one element from the second and one from the first. + +pair3 :: Gen a -> (a -> Gen a) -> Gen (a, a) +pair3 gen1 gen2 = + oneof [ liftM2 (,) gen1 gen1 + , pair gen1 gen2 + , fmap (snd &&& fst) $ pair gen1 gen2 + ] }