Revision 22fac87d

b/htools/Ganeti/HTools/QC.hs
302 302
prop_Utils_if'if :: Bool -> Int -> Int -> Bool
303 303
prop_Utils_if'if cnd a b = Utils.if' cnd a b == if cnd then a else b
304 304

  
305
-- | Test select
305
-- | Test basic select functionality
306 306
prop_Utils_select :: Int   -- ^ Default result
307 307
                  -> [Int] -- ^ List of False values
308 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 309
                  -> Bool  -- ^ Test result
313
prop_Utils_select di lst1 lst2 rundefd rundeft rundeff =
310
prop_Utils_select def lst1 lst2 =
314 311
  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
312
  where expectedresult = Utils.if' (null lst2) def (head lst2)
323 313
        flist = map (\e -> (False, e)) lst1
324 314
        tlist = map (\e -> (True, e)) lst2
325
        cndlist = flist ++ tlist ++ utl ++ ufl
315
        cndlist = flist ++ tlist
316

  
317
-- | Test basic select functionality with undefined default
318
prop_Utils_select_undefd :: [Int] -- ^ List of False values
319
                         -> NonEmptyList Int -- ^ List of True values
320
                         -> Bool  -- ^ Test result
321
prop_Utils_select_undefd lst1 (NonEmpty lst2) =
322
  Utils.select undefined cndlist == head lst2
323
  where flist = map (\e -> (False, e)) lst1
324
        tlist = map (\e -> (True, e)) lst2
325
        cndlist = flist ++ tlist
326

  
327
-- | Test basic select functionality with undefined list values
328
prop_Utils_select_undefv :: [Int] -- ^ List of False values
329
                         -> NonEmptyList Int -- ^ List of True values
330
                         -> Bool  -- ^ Test result
331
prop_Utils_select_undefv lst1 (NonEmpty lst2) =
332
  Utils.select undefined cndlist == head lst2
333
  where flist = map (\e -> (False, e)) lst1
334
        tlist = map (\e -> (True, e)) lst2
335
        cndlist = flist ++ tlist ++ [undefined]
326 336

  
327 337
-- | Test list for the Utils module.
328 338
testUtils =
......
331 341
  , run prop_Utils_fromObjWithDefault
332 342
  , run prop_Utils_if'if
333 343
  , run prop_Utils_select
344
  , run prop_Utils_select_undefd
345
  , run prop_Utils_select_undefv
334 346
  ]
335 347

  
336 348
-- ** PeerMap tests

Also available in: Unified diff