Revision 8e4f6d56 htools/Ganeti/HTools/QC.hs

b/htools/Ganeti/HTools/QC.hs
37 37
    ) where
38 38

  
39 39
import Test.QuickCheck
40
import Test.QuickCheck.Batch
41 40
import Data.List (findIndex, intercalate, nub, isPrefixOf)
42 41
import Data.Maybe
43 42
import Control.Monad
......
66 65
import qualified Ganeti.HTools.Version
67 66
import qualified Ganeti.Constants as C
68 67

  
68
run :: Testable prop => prop -> Args -> IO Result
69
run = flip quickCheckWithResult
70

  
69 71
-- * Constants
70 72

  
71 73
-- | Maximum memory (1TiB, somewhat random value)
......
147 149

  
148 150
-- * Arbitrary instances
149 151

  
150
-- copied from the introduction to quickcheck
151
instance Arbitrary Char where
152
    arbitrary = choose ('\32', '\128')
153

  
154 152
newtype DNSChar = DNSChar { dnsGetChar::Char }
155 153
instance Arbitrary DNSChar where
156 154
    arbitrary = do
......
500 498
prop_Text_Load_InstanceFail ktn fields =
501 499
    length fields /= 9 ==>
502 500
    case Text.loadInst nl fields of
503
      Right _ -> False
504
      Left msg -> isPrefixOf "Invalid/incomplete instance data: '" msg
501
      Types.Ok _ -> False
502
      Types.Bad msg -> "Invalid/incomplete instance data: '" `isPrefixOf` msg
505 503
    where nl = Data.Map.fromList ktn
506 504

  
507 505
prop_Text_Load_Node name tm nm fm td fd tc fo =
......
703 701
-- Cluster tests
704 702

  
705 703
-- | Check that the cluster score is close to zero for a homogeneous cluster
706
prop_Score_Zero node count =
704
prop_Score_Zero node =
705
    forAll (choose (1, 1024)) $ \count ->
707 706
    (not (Node.offline node) && not (Node.failN1 node) && (count > 0) &&
708 707
     (Node.tDsk node > 0) && (Node.tMem node > 0)) ==>
709 708
    let fn = Node.buildPeers node Container.empty
......
712 711
        score = Cluster.compCV nl
713 712
    -- we can't say == 0 here as the floating point errors accumulate;
714 713
    -- this should be much lower than the default score in CLI.hs
715
    in score <= 1e-15
714
    in score <= 1e-12
716 715

  
717 716
-- | Check that cluster stats are sane
718
prop_CStats_sane node count =
719
    (not (Node.offline node) && not (Node.failN1 node) && (count > 0) &&
717
prop_CStats_sane node =
718
    forAll (choose (1, 1024)) $ \count ->
719
    (not (Node.offline node) && not (Node.failN1 node) &&
720 720
     (Node.availDisk node > 0) && (Node.availMem node > 0)) ==>
721 721
    let fn = Node.buildPeers node Container.empty
722 722
        nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]

Also available in: Unified diff