public void RunsEnterInitExitFunctionsInProperOrder() { BehaviorMap behaviors = new BehaviorMap(); List <string> list = new List <string>(); Callback callback = (stateName) => { list.Add(stateName); }; MakeCallbacks( behaviors, new[] { "Root", "opened", "closed", "locked", "unlocked" }, new[] { "init", "enter", "exit" }, callback ); StateChart chart = GetChart(behaviors); Assert.That(list, Is.EquivalentTo(new[] { "Root:init", "Root:enter", "closed:init", "closed:enter", "locked:init", "locked:enter" })); list.Clear(); chart.Trigger(new Evt_DoorUnlock()); chart.Tick(); Assert.That(list, Is.EquivalentTo(new[] { "locked:exit", "unlocked:init", "unlocked:enter" })); list.Clear(); chart.Trigger(new Evt_DoorLock()); chart.Tick(); Assert.That(list, Is.EquivalentTo(new[] { "unlocked:exit", "locked:enter" })); }
public void TransitionsToAnotherState() { StateChart chart = new StateChart((builder) => { Action <string, Action> State = builder.State; State("State-1", () => { builder.Transition <SomeEvt>("State-1-2"); State("State-1-1", () => { State("State-1-1-1", () => { }); State("State-1-1-2", () => { }); }); State("State-1-2", () => { }); }); }); chart.Trigger(new SomeEvt()); chart.Tick(); Assert.IsTrue(chart.IsInState("State-1")); Assert.IsFalse(chart.IsInState("State-1-1")); Assert.IsFalse(chart.IsInState("State-1-1-1")); Assert.IsFalse(chart.IsInState("State-1-1-2")); Assert.IsTrue(chart.IsInState("State-1-2")); }
public void MovesFromClosedAndUnlockedToOpenedAndBackToClosedLocked() { StateChart chart = GetChart(); chart.Trigger(new Evt_DoorUnlock()); chart.Trigger(new Evt_DoorOpen()); chart.Tick(); Assert.IsTrue(chart.IsInState("opened")); Assert.IsFalse(chart.IsInState("closed")); Assert.IsFalse(chart.IsInState("locked")); Assert.IsFalse(chart.IsInState("unlocked")); chart.Trigger(new Evt_DoorClose()); chart.Tick(); Assert.IsFalse(chart.IsInState("opened")); Assert.IsTrue(chart.IsInState("closed")); Assert.IsFalse(chart.IsInState("locked")); Assert.IsTrue(chart.IsInState("unlocked")); }
public void CallsEventHandlers() { List <string> list = new List <string>(); Action <string, StateChartEvent> callback = (key, evt) => { list.Add(key); }; EvtPair[] pairs = { new EvtPair("Root", typeof(Evt_DoorUnlock), callback), new EvtPair("closed", typeof(Evt_DoorUnlock), callback), new EvtPair("locked", typeof(Evt_DoorUnlock), callback), new EvtPair("unlocked", typeof(Evt_DoorUnlock), callback), new EvtPair("opened", typeof(Evt_DoorUnlock), callback), new EvtPair("Root", typeof(Evt_DoorLock), callback), new EvtPair("closed", typeof(Evt_DoorLock), callback), new EvtPair("locked", typeof(Evt_DoorLock), callback), new EvtPair("unlocked", typeof(Evt_DoorLock), callback) }; StateChart chart = GetChart(null, pairs); chart.Trigger(new Evt_DoorUnlock()); chart.Tick(); Assert.That(list, Is.EquivalentTo(new[] { "Root:Evt_DoorUnlock", "closed:Evt_DoorUnlock", "locked:Evt_DoorUnlock" })); list.Clear(); chart.Trigger(new Evt_DoorUnlock()); chart.Trigger(new Evt_DoorLock()); chart.Tick(); Assert.That(list, Is.EquivalentTo(new[] { "Root:Evt_DoorUnlock", "closed:Evt_DoorUnlock", "unlocked:Evt_DoorUnlock", "Root:Evt_DoorLock", "closed:Evt_DoorLock", "unlocked:Evt_DoorLock" })); }
public void DoesNotTransitionIfGuardFnIsFalse() { StateChart chart = GetChart(); chart.Trigger(new Evt_DoorUnlock(false)); chart.Tick(); Assert.IsFalse(chart.IsInState("unlocked")); Assert.IsTrue(chart.IsInState("closed")); Assert.IsFalse(chart.IsInState("opened")); Assert.IsTrue(chart.IsInState("locked")); }
public void DoesNotTransitionIfNoTransitionHandlerExistsForCongiuration() { StateChart chart = GetChart(); chart.Trigger(new Evt_DoorOpen()); chart.Tick(); Assert.IsFalse(chart.IsInState("opened")); Assert.IsTrue(chart.IsInState("closed")); Assert.IsTrue(chart.IsInState("locked")); Assert.IsFalse(chart.IsInState("unlocked")); }
public void MovesToUnlockedFromClosedWithUnlockEvent() { StateChart chart = GetChart(); chart.Trigger(new Evt_DoorUnlock()); chart.Tick(); Assert.IsTrue(chart.IsInState("unlocked")); Assert.IsTrue(chart.IsInState("closed")); Assert.IsFalse(chart.IsInState("opened")); Assert.IsFalse(chart.IsInState("locked")); }
private void OnStateChartSignal(Match3Signals.StateChartSignal signal) { stateChart.Trigger(signal._stateMachineEvent); }
private void OnExitToMap() { stateChart.Trigger(GameStateEvents.ExitBoardEvent); }