public void Setup() { var builder = new StateControllerBuilder <TestState, TestContext>() .WithDefaultState(A) .AddState(B) .AddState(C) .AddState(D) .AddState(E) .AddState(F); A.AddTransition(B, ctx => ctx.B > 10); A.AddTransition(C, ctx => ctx.C > 10); B.AddTransition(C, ctx => ctx.B > 20); B.AddTransition(D, ctx => ctx.C > 20); C.AddTransition(D, ctx => ctx.B > 30); C.AddTransition(E, ctx => ctx.C > 30); D.AddTransition(E, ctx => ctx.B > 40); D.AddTransition(F, ctx => ctx.C > 40); E.AddTransition(F, ctx => ctx.B > 50); E.AddTransition(A, ctx => ctx.C > 50); F.AddTransition(A, ctx => ctx.B > 50); F.AddTransition(B, ctx => ctx.C > 50); new[] { B, C, D, E, F }.AddTransitions(A, ctx => ctx.A); _controller = builder.Build(); }
public void state_null_transition_defers_to_later_transitions() { var stateA = new TestState(); var stateB = new TestState(); stateA.AddTransition(ctx => null); stateA.AddTransition(ctx => stateB); Assert.AreEqual(stateB, stateA.EvaluateTransitions(new TestContext())); }
public void state_evaluate_transitions_prefers_earlier_transitions() { var stateA = new TestState(); var stateB = new TestState(); var stateC = new TestState(); stateA.AddTransition(ctx => stateB); stateA.AddTransition(ctx => stateC); Assert.AreEqual(stateB, stateA.EvaluateTransitions(new TestContext())); }
public void add_transition_predicate_can_succeed() { var stateA = new TestState(); var stateB = new TestState(); stateA.AddTransition(stateB, ctx => ctx != null); Assert.AreEqual(stateB, stateA.EvaluateTransitions(new object())); Assert.AreEqual(null, stateA.EvaluateTransitions(null)); }
public void state_evaluate_transitions_depends_on_value() { var stateA = new TestState(); var stateB = new TestState(); var stateC = new TestState(); stateA.AddTransition(ctx => { if (ctx.A) { return(stateA); } return(ctx.B ? stateB : null); }); stateA.AddTransition(ctx => stateC); Assert.AreEqual(stateC, stateA.EvaluateTransitions(new TestContext())); Assert.AreEqual(stateA, stateA.EvaluateTransitions(new TestContext { A = true })); Assert.AreEqual(stateB, stateA.EvaluateTransitions(new TestContext { B = true })); }
public void SuccessfulStateTransitionsSetCurrentState() { TestState defaultState = new TestState("DefaultTestState"); mTestStateMachine.EnterInitialState(defaultState); TestState testState = new TestState("TestState01"); defaultState.AddTransition(testState); testState.AddTransition(defaultState); mTestStateMachine.TransitionToState(testState.Name); mTestStateMachine.TransitionToState(defaultState.Name); mTestStateMachine.TransitionToState(testState.Name); Assert.AreEqual(2u, defaultState.EnterCount); Assert.AreEqual(2u, defaultState.ExitCount); Assert.AreEqual(2u, testState.EnterCount); Assert.AreEqual(1u, testState.ExitCount); }