Revision df8578fb htest/Test/Ganeti/TestCommon.hs

b/htest/Test/Ganeti/TestCommon.hs
187 187
  vectorOf n genName
188 188

  
189 189
-- | Generates a list of a given size with non-duplicate elements.
190
genUniquesList :: (Eq a, Arbitrary a) => Int -> Gen [a]
191
genUniquesList cnt =
192
  foldM (\lst _ -> do
193
           newelem <- arbitrary `suchThat` (`notElem` lst)
194
           return (newelem:lst)) [] [1..cnt]
190
genUniquesList :: (Eq a, Arbitrary a, Ord a) => Int -> Gen a -> Gen [a]
191
genUniquesList cnt generator = do
192
  set <- foldM (\set _ -> do
193
                  newelem <- generator `suchThat` (`Set.notMember` set)
194
                  return (Set.insert newelem set)) Set.empty [1..cnt]
195
  return $ Set.toList set
195 196

  
196 197
newtype SmallRatio = SmallRatio Double deriving Show
197 198
instance Arbitrary SmallRatio where

Also available in: Unified diff