Revision df8578fb

b/htest/Test/Ganeti/HTools/Container.hs
63 63
  forAll (genNode (Just 1) Nothing) $ \node ->
64 64
  forAll (choose (1, 20)) $ \ cnt ->
65 65
  forAll (choose (0, cnt - 1)) $ \ fidx ->
66
  forAll (genUniquesList (cnt * 2)) $ \ allnames ->
66
  forAll (genUniquesList (cnt * 2) arbitrary) $ \ allnames ->
67 67
  forAll (arbitrary `suchThat` (`notElem` allnames)) $ \ othername ->
68 68
  let names = zip (take cnt allnames) (drop cnt allnames)
69 69
      nl = makeSmallCluster node cnt
b/htest/Test/Ganeti/HTools/Types.hs
106 106
    istd <- genBiggerISpec imin
107 107
    imax <- genBiggerISpec istd
108 108
    num_tmpl <- choose (0, length allDiskTemplates)
109
    dts  <- genUniquesList num_tmpl
109
    dts  <- genUniquesList num_tmpl arbitrary
110 110
    vcpu_ratio <- choose (1.0, maxVcpuRatio)
111 111
    spindle_ratio <- choose (1.0, maxSpindleRatio)
112 112
    return Types.IPolicy { Types.iPolicyMinSpec = imin
b/htest/Test/Ganeti/OpCodes.hs
360 360
genDiskIndices :: Gen [DiskIndex]
361 361
genDiskIndices = do
362 362
  cnt <- choose (0, C.maxDisks)
363
  genUniquesList cnt
363
  genUniquesList cnt arbitrary
364 364

  
365 365
-- | Generates a list of node names.
366 366
genNodeNames :: Gen [String]
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