Of the three tests below which is the best test for transitivity. This follows from my previous question. The usual logical rule of transitivity (R(a,b) and R(b,c)) => R(a,c) does not seem apply in this case.Hence, I think that prop_trans3
would be not be a good test, because each of the three terms represents a different stack. But which of prop_trans1
and prop_trans2
are best suited to testing transitivity?
import Test.QuickCheck
data Block = Block Int deriving (Show,Eq)
-- MoveOnto(bl,b2,s) is read as b2 is moved into and onto bl on stack or table.
data Stack = EmptyTable | MoveOnto Block Block Stack deriving (Show,Eq)
isOn :: Block -> Block -> Stack -> Bool
isOn b1 b2 (MoveOnto b3 b4 s) | ((b1 == b3) && (b4 == b2)) || (isOn b4 b2 s) = True
isOn _ _ _ = False
instance Arbitrary (Block) where
arbitrary = fmap Block arbitrary
instance Arbitrary (Stack) where
arbitrary = oneof [return EmptyTable, MoveOnto <$> arbitrary <*> arbitrary <*> arbitrary]
prop_trans1 b1 b2 s = isOn b1 b2 (MoveOnto b1 b2 s)
prop_trans2 b1 b2 b3 s = isOn b3 b1 (MoveOnto b3 b2 (MoveOnto b2 b1 s))
prop_trans3 b1 b2 b3 s = ((isOn b2 b1 (MoveOnto b2 b1 s)) && (isOn b3 b2 (MoveOnto b3 b2 s))) <= (isOn b3 b1 (MoveOnto b3 b1 s))
Aucun commentaire:
Enregistrer un commentaire