Revision 01e52493 htest/Test/Ganeti/Utils.hs

b/htest/Test/Ganeti/Utils.hs
28 28

  
29 29
module Test.Ganeti.Utils (testUtils) where
30 30

  
31
import Test.QuickCheck
31
import Test.QuickCheck hiding (Result)
32 32
import Test.HUnit
33 33

  
34 34
import Data.List
......
37 37
import Test.Ganeti.TestHelper
38 38
import Test.Ganeti.TestCommon
39 39

  
40
import Ganeti.BasicTypes
40 41
import qualified Ganeti.JSON as JSON
41
import qualified Ganeti.HTools.Types as Types
42 42
import Ganeti.Utils
43 43

  
44 44
-- | Helper to generate a small string that doesn't contain commas.
......
107 107

  
108 108
prop_parseUnit :: NonNegative Int -> Property
109 109
prop_parseUnit (NonNegative n) =
110
  parseUnit (show n) ==? Types.Ok n .&&.
111
  parseUnit (show n ++ "m") ==? Types.Ok n .&&.
112
  parseUnit (show n ++ "M") ==? Types.Ok (truncate n_mb::Int) .&&.
113
  parseUnit (show n ++ "g") ==? Types.Ok (n*1024) .&&.
114
  parseUnit (show n ++ "G") ==? Types.Ok (truncate n_gb::Int) .&&.
115
  parseUnit (show n ++ "t") ==? Types.Ok (n*1048576) .&&.
116
  parseUnit (show n ++ "T") ==? Types.Ok (truncate n_tb::Int) .&&.
117
  printTestCase "Internal error/overflow?"
118
    (n_mb >=0 && n_gb >= 0 && n_tb >= 0) .&&.
119
  property (Types.isBad (parseUnit (show n ++ "x")::Types.Result Int))
110
  conjoin
111
  [ parseUnit (show n) ==? (Ok n::Result Int)
112
  , parseUnit (show n ++ "m") ==? (Ok n::Result Int)
113
  , parseUnit (show n ++ "M") ==? (Ok (truncate n_mb)::Result Int)
114
  , parseUnit (show n ++ "g") ==? (Ok (n*1024)::Result Int)
115
  , parseUnit (show n ++ "G") ==? (Ok (truncate n_gb)::Result Int)
116
  , parseUnit (show n ++ "t") ==? (Ok (n*1048576)::Result Int)
117
  , parseUnit (show n ++ "T") ==? (Ok (truncate n_tb)::Result Int)
118
  , printTestCase "Internal error/overflow?"
119
    (n_mb >=0 && n_gb >= 0 && n_tb >= 0)
120
  , property (isBad (parseUnit (show n ++ "x")::Result Int))
121
  ]
120 122
  where n_mb = (fromIntegral n::Rational) * 1000 * 1000 / 1024 / 1024
121 123
        n_gb = n_mb * 1000
122 124
        n_tb = n_gb * 1000

Also available in: Unified diff