Revision 0047d4e2
b/htools/Ganeti/HTools/QC.hs  

279  279 
instance Arbitrary Types.DiskTemplate where 
280  280 
arbitrary = elements [minBound..maxBound] 
281  281  
282 
instance Arbitrary Types.FailMode where 

283 
arbitrary = elements [minBound..maxBound] 

284  
285 
instance Arbitrary a => Arbitrary (Types.OpResult a) where 

286 
arbitrary = arbitrary >>= \c > 

287 
case c of 

288 
False > liftM Types.OpFail arbitrary 

289 
True > liftM Types.OpGood arbitrary 

290  
282  291 
 * Actual tests 
283  292  
284  293 
 ** Utils tests 
...  ...  
1045  1054  
1046  1055 
 ** Types tests 
1047  1056  
1048 
prop_AllocPolicy_serialisation apol = 

1049 
case Types.apolFromString (Types.apolToString apol) of 

1050 
Types.Ok p > printTestCase ("invalid deserialisation " ++ show p) $ 

1051 
p == apol 

1052 
Types.Bad s > printTestCase ("failed to deserialise: " ++ s) False 

1053  
1054 
prop_DiskTemplate_serialisation dt = 

1055 
case Types.dtFromString (Types.dtToString dt) of 

1056 
Types.Ok p > printTestCase ("invalid deserialisation " ++ show p) $ 

1057 
p == dt 

1058 
Types.Bad s > printTestCase ("failed to deserialise: " ++ s) False 

1057 
prop_Types_AllocPolicy_serialisation apol = 

1058 
case J.readJSON (J.showJSON apol) of 

1059 
J.Ok p > printTestCase ("invalid deserialisation " ++ show p) $ 

1060 
p == apol 

1061 
J.Error s > printTestCase ("failed to deserialise: " ++ s) False 

1062 
where _types = apol::Types.AllocPolicy 

1063  
1064 
prop_Types_DiskTemplate_serialisation dt = 

1065 
case J.readJSON (J.showJSON dt) of 

1066 
J.Ok p > printTestCase ("invalid deserialisation " ++ show p) $ 

1067 
p == dt 

1068 
J.Error s > printTestCase ("failed to deserialise: " ++ s) 

1069 
False 

1070 
where _types = dt::Types.DiskTemplate 

1071  
1072 
prop_Types_opToResult op = 

1073 
case op of 

1074 
Types.OpFail _ > Types.isBad r 

1075 
Types.OpGood v > case r of 

1076 
Types.Bad _ > False 

1077 
Types.Ok v' > v == v' 

1078 
where r = Types.opToResult op 

1079 
_types = op::Types.OpResult Int 

1080  
1081 
prop_Types_eitherToResult ei = 

1082 
case ei of 

1083 
Left _ > Types.isBad r 

1084 
Right v > case r of 

1085 
Types.Bad _ > False 

1086 
Types.Ok v' > v == v' 

1087 
where r = Types.eitherToResult ei 

1088 
_types = ei::Either String Int 

1059  1089  
1060  1090 
testTypes = 
1061 
[ run prop_AllocPolicy_serialisation 

1062 
, run prop_DiskTemplate_serialisation 

1091 
[ run prop_Types_AllocPolicy_serialisation 

1092 
, run prop_Types_DiskTemplate_serialisation 

1093 
, run prop_Types_opToResult 

1094 
, run prop_Types_eitherToResult 

1063  1095 
] 
Also available in: Unified diff