software-engineering-amsterdam / ST2017_WG_4

0 stars 0 forks source link

Lab 3: Ex. 4 #5

Open BertLisser opened 7 years ago

BertLisser commented 7 years ago
arbitrarySizedForm :: Int -> Gen Form
arbitrarySizedForm n
  | n <= 0    = do
    t  <- arbitrary
    return (Prop t)
  | n > 0     =  oneof [liftM Neg subForm,
         liftM Cnj subFormBracets,
         liftM Dsj subFormBracets,
         liftM2 Impl subForm subForm,
         liftM2 Equiv subForm subForm]
       where subForm        = arbitrarySizedForm (n `div` 2)
subFormBracets = listOf1 (arbitrarySizedForm (n `div` 4))

Better

arbitrarySizedForm :: Int -> Gen Form
arbitrarySizedForm n
  | n <= 0    = do
    t  <- arbitrary
    return (Prop t)
  | n > 0     =  oneof [liftM Neg subForm,
         liftM Cnj subFormBracets,
         liftM Dsj subFormBracets,
         liftM2 Impl subForm subForm,
         liftM2 Equiv subForm subForm]
       where subForm        = arbitrarySizedForm (n `div` 2)
subFormBracets = listOf (arbitrarySizedForm (n `div` 4))

Empty list of arguments at Cnjand Dsj are allowed.

quickCheck (withMaxSuccess 10 prop_checkEquiv)
quickCheck (withMaxSuccess 10 prop_checkCNF)

Better is

quickCheck (withMaxSize 5 prop_checkEquiv)
quickCheck (withMaxSize 5 prop_checkCNF)

This generates more tests with smaller samples.

Well done! (=9)