Revision 20bc5360 htest/Test/Ganeti/HTools/Utils.hs

b/htest/Test/Ganeti/HTools/Utils.hs
47 47

  
48 48
-- | If the list is not just an empty element, and if the elements do
49 49
-- not contain commas, then join+split should be idempotent.
50
prop_Utils_commaJoinSplit :: Property
51
prop_Utils_commaJoinSplit =
50
prop_commaJoinSplit :: Property
51
prop_commaJoinSplit =
52 52
  forAll (choose (0, 20)) $ \llen ->
53 53
  forAll (vectorOf llen genNonCommaString `suchThat` ((/=) [""])) $ \lst ->
54 54
  Utils.sepSplit ',' (Utils.commaJoin lst) ==? lst
55 55

  
56 56
-- | Split and join should always be idempotent.
57
prop_Utils_commaSplitJoin :: [Char] -> Property
58
prop_Utils_commaSplitJoin s =
57
prop_commaSplitJoin :: [Char] -> Property
58
prop_commaSplitJoin s =
59 59
  Utils.commaJoin (Utils.sepSplit ',' s) ==? s
60 60

  
61 61
-- | fromObjWithDefault, we test using the Maybe monad and an integer
62 62
-- value.
63
prop_Utils_fromObjWithDefault :: Integer -> String -> Bool
64
prop_Utils_fromObjWithDefault def_value random_key =
63
prop_fromObjWithDefault :: Integer -> String -> Bool
64
prop_fromObjWithDefault def_value random_key =
65 65
  -- a missing key will be returned with the default
66 66
  JSON.fromObjWithDefault [] random_key def_value == Just def_value &&
67 67
  -- a found key will be returned as is, not with default
......
69 69
       random_key (def_value+1) == Just def_value
70 70

  
71 71
-- | Test that functional if' behaves like the syntactic sugar if.
72
prop_Utils_if'if :: Bool -> Int -> Int -> Gen Prop
73
prop_Utils_if'if cnd a b =
72
prop_if'if :: Bool -> Int -> Int -> Gen Prop
73
prop_if'if cnd a b =
74 74
  Utils.if' cnd a b ==? if cnd then a else b
75 75

  
76 76
-- | Test basic select functionality
77
prop_Utils_select :: Int      -- ^ Default result
78
                  -> [Int]    -- ^ List of False values
79
                  -> [Int]    -- ^ List of True values
80
                  -> Gen Prop -- ^ Test result
81
prop_Utils_select def lst1 lst2 =
77
prop_select :: Int      -- ^ Default result
78
            -> [Int]    -- ^ List of False values
79
            -> [Int]    -- ^ List of True values
80
            -> Gen Prop -- ^ Test result
81
prop_select def lst1 lst2 =
82 82
  Utils.select def (flist ++ tlist) ==? expectedresult
83 83
    where expectedresult = Utils.if' (null lst2) def (head lst2)
84 84
          flist = zip (repeat False) lst1
85 85
          tlist = zip (repeat True)  lst2
86 86

  
87 87
-- | Test basic select functionality with undefined default
88
prop_Utils_select_undefd :: [Int]            -- ^ List of False values
89
                         -> NonEmptyList Int -- ^ List of True values
90
                         -> Gen Prop         -- ^ Test result
91
prop_Utils_select_undefd lst1 (NonEmpty lst2) =
88
prop_select_undefd :: [Int]            -- ^ List of False values
89
                   -> NonEmptyList Int -- ^ List of True values
90
                   -> Gen Prop         -- ^ Test result
91
prop_select_undefd lst1 (NonEmpty lst2) =
92 92
  Utils.select undefined (flist ++ tlist) ==? head lst2
93 93
    where flist = zip (repeat False) lst1
94 94
          tlist = zip (repeat True)  lst2
95 95

  
96 96
-- | Test basic select functionality with undefined list values
97
prop_Utils_select_undefv :: [Int]            -- ^ List of False values
98
                         -> NonEmptyList Int -- ^ List of True values
99
                         -> Gen Prop         -- ^ Test result
100
prop_Utils_select_undefv lst1 (NonEmpty lst2) =
97
prop_select_undefv :: [Int]            -- ^ List of False values
98
                   -> NonEmptyList Int -- ^ List of True values
99
                   -> Gen Prop         -- ^ Test result
100
prop_select_undefv lst1 (NonEmpty lst2) =
101 101
  Utils.select undefined cndlist ==? head lst2
102 102
    where flist = zip (repeat False) lst1
103 103
          tlist = zip (repeat True)  lst2
104 104
          cndlist = flist ++ tlist ++ [undefined]
105 105

  
106
prop_Utils_parseUnit :: NonNegative Int -> Property
107
prop_Utils_parseUnit (NonNegative n) =
106
prop_parseUnit :: NonNegative Int -> Property
107
prop_parseUnit (NonNegative n) =
108 108
  Utils.parseUnit (show n) ==? Types.Ok n .&&.
109 109
  Utils.parseUnit (show n ++ "m") ==? Types.Ok n .&&.
110 110
  Utils.parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&.
......
121 121

  
122 122
-- | Test list for the Utils module.
123 123
testSuite "Utils"
124
            [ 'prop_Utils_commaJoinSplit
125
            , 'prop_Utils_commaSplitJoin
126
            , 'prop_Utils_fromObjWithDefault
127
            , 'prop_Utils_if'if
128
            , 'prop_Utils_select
129
            , 'prop_Utils_select_undefd
130
            , 'prop_Utils_select_undefv
131
            , 'prop_Utils_parseUnit
124
            [ 'prop_commaJoinSplit
125
            , 'prop_commaSplitJoin
126
            , 'prop_fromObjWithDefault
127
            , 'prop_if'if
128
            , 'prop_select
129
            , 'prop_select_undefd
130
            , 'prop_select_undefv
131
            , 'prop_parseUnit
132 132
            ]

Also available in: Unified diff