Revision 1cdcf8f3 htools/Ganeti/HTools/QC.hs
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
537 | 537 |
cndlist = flist ++ tlist ++ [undefined] |
538 | 538 |
|
539 | 539 |
prop_Utils_parseUnit (NonNegative n) = |
540 |
Utils.parseUnit (show n) == Types.Ok n && |
|
541 |
Utils.parseUnit (show n ++ "m") == Types.Ok n && |
|
542 |
(case Utils.parseUnit (show n ++ "M") of |
|
543 |
Types.Ok m -> if n > 0 |
|
544 |
then m < n -- for positive values, X MB is < than X MiB |
|
545 |
else m == 0 -- but for 0, 0 MB == 0 MiB |
|
546 |
Types.Bad _ -> False) && |
|
547 |
Utils.parseUnit (show n ++ "g") == Types.Ok (n*1024) && |
|
548 |
Utils.parseUnit (show n ++ "t") == Types.Ok (n*1048576) && |
|
549 |
Types.isBad (Utils.parseUnit (show n ++ "x")::Types.Result Int) |
|
550 |
where _types = n::Int |
|
540 |
Utils.parseUnit (show n) ==? Types.Ok n .&&. |
|
541 |
Utils.parseUnit (show n ++ "m") ==? Types.Ok n .&&. |
|
542 |
Utils.parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&. |
|
543 |
Utils.parseUnit (show n ++ "g") ==? Types.Ok (n*1024) .&&. |
|
544 |
Utils.parseUnit (show n ++ "G") ==? Types.Ok (truncate n_gb::Int) .&&. |
|
545 |
Utils.parseUnit (show n ++ "t") ==? Types.Ok (n*1048576) .&&. |
|
546 |
Utils.parseUnit (show n ++ "T") ==? Types.Ok (truncate n_tb::Int) .&&. |
|
547 |
printTestCase "Internal error/overflow?" |
|
548 |
(n_mb >=0 && n_gb >= 0 && n_tb >= 0) .&&. |
|
549 |
property (Types.isBad (Utils.parseUnit (show n ++ "x")::Types.Result Int)) |
|
550 |
where _types = (n::Int) |
|
551 |
n_mb = (fromIntegral n::Rational) * 1000 * 1000 / 1024 / 1024 |
|
552 |
n_gb = n_mb * 1000 |
|
553 |
n_tb = n_gb * 1000 |
|
551 | 554 |
|
552 | 555 |
-- | Test list for the Utils module. |
553 | 556 |
testSuite "Utils" |
Also available in: Unified diff