Revision bfe6c954 htools/Ganeti/HTools/QC.hs

b/htools/Ganeti/HTools/QC.hs
298 298
         random_key (def_value+1) == Just def_value
299 299
        where _types = def_value :: Integer
300 300

  
301
-- | Test that functional if' behaves like the syntactic sugar if.
302
prop_Utils_if'if :: Bool -> Int -> Int -> Bool
303
prop_Utils_if'if cnd a b = Utils.if' cnd a b == if cnd then a else b
304

  
305
-- | Test select
306
prop_Utils_select :: Int   -- ^ Default result
307
                  -> [Int] -- ^ List of False values
308
                  -> [Int] -- ^ List of True values
309
                  -> Bool  -- ^ Try undef result (if a true value exists)
310
                  -> Bool  -- ^ Try undef true value (if a true value exists)
311
                  -> Bool  -- ^ Try undef false value (if a true value exists)
312
                  -> Bool  -- ^ Test result
313
prop_Utils_select di lst1 lst2 rundefd rundeft rundeff =
314
  Utils.select def cndlist == expectedresult
315
  where has_nondef_result = not (null lst2)
316
        try_undefd = has_nondef_result && rundefd
317
        try_undeft = has_nondef_result && rundeft
318
        try_undeff = has_nondef_result && rundeff
319
        def = Utils.if' try_undefd undefined di
320
        utl = Utils.if' try_undeft [(True, undefined)] []
321
        ufl = Utils.if' try_undeff [(False, undefined)] []
322
        expectedresult = Utils.if' has_nondef_result (head lst2) def
323
        flist = map (\e -> (False, e)) lst1
324
        tlist = map (\e -> (True, e)) lst2
325
        cndlist = flist ++ tlist ++ utl ++ ufl
326

  
301 327
-- | Test list for the Utils module.
302 328
testUtils =
303 329
  [ run prop_Utils_commaJoinSplit
304 330
  , run prop_Utils_commaSplitJoin
305 331
  , run prop_Utils_fromObjWithDefault
332
  , run prop_Utils_if'if
333
  , run prop_Utils_select
306 334
  ]
307 335

  
308 336
-- ** PeerMap tests

Also available in: Unified diff