Testing the state machine
At the beginning of this chapter, we saw an image of one possible solution to the puzzle. Letβs write a test to verify that the update function follows this solution:
specWalk :: Spec Unit
specWalk =
it "should follow the walk and visit the expected intermediate states" do
assertWalk update
(v @"1")
[ v @"f" ~> v @"3"
, v @"h" ~> v @"4"
, v @"g" ~> v @"2"
, v @"a" ~> v @"1"
, v @"e" ~> v @"4"
, v @"d" ~> v @"5"
, v @"c" ~> v @"3"
, v @"b" ~> v @"2"
]π test/Examples/HouseSantaClaus.purs L68-L81
Since this test passes, we know that the state machine has an
Eulerian trail. We can also assert that with the
hasEulerTrail function we defined earlier:
specEulerTrail :: Spec Unit
specEulerTrail =
it "should have an Eulerian trail" do
let
graph :: StateGraph
graph = mkStateGraph santaTransit
hasEulerTrail graph `shouldEqual` true