{-# OPTIONS_GHC -Wno-incomplete-patterns #-} {-# OPTIONS_GHC -Wno-missing-signatures #-} module StateCoverTests where import Data.Map.Strict qualified as Map import Data.Maybe (mapMaybe) import StateCover.Simultaneous import StateCover.StateCover import Test.Tasty import Test.Tasty.HUnit type PMealy s i o = s -> [((i, o), s)] g0 :: PMealy Int Char Int g0 0 = [(('a', 0), 1)] g0 1 = [(('b', 0), 2)] g0 2 = [(('c', 0), 0)] g1 :: PMealy Int Char Int g1 0 = [(('a', 0), 1), (('d', 0), 2)] g1 1 = [(('b', 0), 2)] g1 2 = [(('c', 0), 0)] c0 :: IGraph Int Char c0 0 'x' = Just 0 c0 0 _ = Just 1 c0 1 'x' = Just 2 c0 _ _ = Just 0 c1 :: IGraph Int Char c1 0 'y' = Just 0 c1 0 _ = Just 1 c1 1 'y' = Just 2 c1 _ _ = Just 0 conv :: [i] -> IGraph s i -> Graph s i conv inputs fun s = mapMaybe (\i -> (i,) <$> fun s i) inputs stateCoverTests = testGroup "state covers" [ testCase "g0" $ stateCover g0 0 @?= Map.fromList [(0, ""), (1, "a"), (2, "ab")] , testCase "g1" $ stateCover g1 0 @?= Map.fromList [(0, ""), (1, "a"), (2, "d")] , testCase "c0" $ bfs (conv "xyz" c0) 0 @?= Map.fromList [(0, ""), (1, "y"), (2, "xy")] , testCase "c1" $ bfs (conv "xyz" c1) 0 @?= Map.fromList [(0, ""), (1, "x"), (2, "yx")] , testCase "c0" $ bfs (conv "zyx" c0) 0 @?= Map.fromList [(0, ""), (1, "z"), (2, "xz")] , testCase "c1" $ bfs (conv "zyx" c1) 0 @?= Map.fromList [(0, ""), (1, "z"), (2, "yz")] , testCase "simul c0 c1" $ simultaneousStateCover [c0, c1] "xyz" [0, 0] @?= [Map.fromList [(0, ""), (1, "z"), (2, "zx")], Map.fromList [(0, ""), (1, "z"), (2, "zy")]] , testCase "simul c0 c1" $ simultaneousStateCover [c0, c1] "zyx" [0, 0] @?= [Map.fromList [(0, ""), (1, "z"), (2, "zx")], Map.fromList [(0, ""), (1, "z"), (2, "zy")]] ]