-- HUnit unit tests for Data.FsmActions.FsmMatrix -- Copyright (c) 2009 Andy Gimblett - http://www.cs.swan.ac.uk/~csandy/ -- BSD Licence (see http://www.opensource.org/licenses/bsd-license.php) module Tests.Data.FsmActions.FsmMatrix ( tests, eg2, eg3, egA ) where import Test.HUnit.Base import Data.FsmActions import Data.FsmActions.Error import Data.FsmActions.FsmMatrix -- nb: If no states are specified, the FSM produced is entirely empty; -- we have no concept of an `empty action', so we will, in effect, -- ignore the action names. eg1txt :: String eg1txt = "a b c\n" eg2txt :: String eg2txt = "a b c\n0 1 0\n1 0 1" eg2 :: FSM String eg2 = fromList [("a", mkDAction [0,1]), ("b", mkDAction [1,0]), ("c", mkDAction [0,1])] eg3 :: FSM String eg3 = fromList [("a", mkDAction [1,2,0]) ,("b", mkDAction [0,1,2]) ,("c", mkDAction [2,0,2]) ] -- Check for failure with too few states on some line. eg3txt :: String eg3txt = "a b c\n0 1 0\n1 0" -- Check for failure with too many states on some line. eg4txt :: String eg4txt = "a b c\n0 1 0\n1 0 1 0" -- Check for failure with same number of states on every line, -- but doesn't match number of actions. eg5txt :: String eg5txt = "a b c\n0 1\n1 0" egA :: IO (FSM String) egA = loadFsmMx "doc/examples/egA.FsmMatrix" tests :: Test tests = test [ "eg1" ~: parseFsmMx eg1txt ~?= Left (FsmError "FSM disconnected" "[]") ,"eg2" ~: parseFsmMx eg2txt ~?= Right eg2 ,"eg3" ~: parseFsmMx eg3txt ~?= Left (FsmError "FSM matrix ill-formed" "[3,2]") ,"eg4" ~: parseFsmMx eg4txt ~?= Left (FsmError "FSM matrix ill-formed" "[3,4]") ,"eg5" ~: parseFsmMx eg5txt ~?= Left (FsmError "FSM matrix ill-formed" "[2,2]") ,"egA" ~: do r <- egA assertBool "14 actions" (length (alphabet r) == 14) assertBool "714 states" (length (states r) == 714) ]