From 5b108e9fbab4f7eb8539282d09e606de807a2a14 Mon Sep 17 00:00:00 2001 From: Joel Schutz Date: Sat, 9 Mar 2024 22:59:18 -0300 Subject: [PATCH] Updates and clean `director` tests --- director_test.go | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/director_test.go b/director_test.go index dcf6d8d..f91d3bb 100644 --- a/director_test.go +++ b/director_test.go @@ -6,17 +6,8 @@ import ( "github.com/stretchr/testify/assert" ) -type DirectidScene struct { - MockScene -} - -func (m *DirectidScene) Load(state int, sm SceneController[int]) { - m.loadCalled = true - m.unloadReturns = state -} - func TestSceneDirector_NewSceneDirector(t *testing.T) { - mockScene := &DirectidScene{} + mockScene := &MockScene{} ruleSet := make(map[Scene[int]][]Directive[int]) director := NewSceneDirector[int](mockScene, 1, ruleSet) @@ -26,8 +17,8 @@ func TestSceneDirector_NewSceneDirector(t *testing.T) { } func TestSceneDirector_ProcessTrigger(t *testing.T) { - mockScene := &DirectidScene{} - mockScene2 := &DirectidScene{} + mockScene := &MockScene{} + mockScene2 := &MockScene{} ruleSet := make(map[Scene[int]][]Directive[int]) director := NewSceneDirector[int](mockScene, 1, ruleSet) @@ -44,14 +35,36 @@ func TestSceneDirector_ProcessTrigger(t *testing.T) { assert.Equal(t, rule.Dest, director.current) } -func TestSceneDirector_ProcessTriggerWiithTransition(t *testing.T) { - mockScene := &DirectidScene{} +func TestSceneDirector_ProcessTriggerWithTransition(t *testing.T) { + mockScene := &MockScene{} + mockTransition := &baseTransitionImplementation{} + ruleSet := make(map[Scene[int]][]Directive[int]) + + director := NewSceneDirector[int](mockScene, 1, ruleSet) + + rule := Directive[int]{Dest: &MockScene{}, Trigger: 2, Transition: mockTransition} + ruleSet[mockScene] = []Directive[int]{rule} + + // Call the ProcessTrigger method with wrong trigger + director.ProcessTrigger(1) + assert.NotEqual(t, rule.Transition, director.current) + + // Call the ProcessTrigger method with correct trigger + director.ProcessTrigger(2) + assert.Equal(t, rule.Transition, director.current) + + rule.Transition.End() + assert.Equal(t, rule.Dest, director.current) +} + +func TestSceneDirector_ProcessTriggerWithTransitionAwareness(t *testing.T) { + mockScene := &MockTransitionAwareScene{} mockTransition := &baseTransitionImplementation{} ruleSet := make(map[Scene[int]][]Directive[int]) director := NewSceneDirector[int](mockScene, 1, ruleSet) - rule := Directive[int]{Dest: &DirectidScene{}, Trigger: 2, Transition: mockTransition} + rule := Directive[int]{Dest: &MockTransitionAwareScene{}, Trigger: 2, Transition: mockTransition} ruleSet[mockScene] = []Directive[int]{rule} // Call the ProcessTrigger method with wrong trigger