Skip to content

Commit

Permalink
Updates Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Schutz committed May 28, 2024
1 parent 46aff38 commit 5d5f883
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
45 changes: 45 additions & 0 deletions director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,48 @@ func TestSceneDirector_ProcessTriggerWithTransitionAwareness(t *testing.T) {
rule.Transition.End()
assert.Equal(t, rule.Dest, director.current)
}

func TestSceneDirector_ProcessTriggerCancelling(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}
director.ProcessTrigger(2)

// Assert transition is running
assert.Equal(t, rule.Transition, director.current)

director.ProcessTrigger(1)
assert.Equal(t, rule.Dest, director.current)
}

func TestSceneDirector_ProcessTriggerCancellingToNewTransition(t *testing.T) {
mockSceneA := &MockScene{}
mockSceneB := &MockScene{}
mockTransitionA := &baseTransitionImplementation{}
mockTransitionB := &baseTransitionImplementation{}
ruleSet := make(map[Scene[int]][]Directive[int])

director := NewSceneDirector[int](mockSceneA, 1, ruleSet)

ruleSet[mockSceneA] = []Directive[int]{
Directive[int]{Dest: mockSceneB, Trigger: 2, Transition: mockTransitionA},
}
ruleSet[mockSceneB] = []Directive[int]{
Directive[int]{Dest: mockSceneA, Trigger: 2, Transition: mockTransitionB},
}
director.ProcessTrigger(2)

// Assert transition is running
assert.Equal(t, mockTransitionA, director.current)

director.ProcessTrigger(2)
assert.Equal(t, mockTransitionB, director.current)

mockTransitionB.End()
assert.Equal(t, mockSceneA, director.current)
}
29 changes: 29 additions & 0 deletions transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ func TestBaseTransition_Awareness(t *testing.T) {
assert.True(t, to.postTransitionCalled)
}

func TestBaseTransition_SwitchCanceling(t *testing.T) {
from := &MockScene{}
to := &MockScene{}
trans := &baseTransitionImplementation{}
sm := NewSceneManager[int](from, 0)
sm.SwitchWithTransition(to, trans)

// Assert transition is running
assert.Equal(t, trans, sm.current)

sm.SwitchTo(to)
assert.Equal(t, to, sm.current)
}

func TestBaseTransition_TransitionCanceling(t *testing.T) {
from := &MockScene{}
to := &MockScene{}
transA := &baseTransitionImplementation{}
transB := &baseTransitionImplementation{}
sm := NewSceneManager[int](from, 0)
sm.SwitchWithTransition(to, transA)

// Assert transition is running
assert.Equal(t, transA, sm.current)

sm.SwitchWithTransition(to, transB)
assert.Equal(t, transB, sm.current)
}

func TestFadeTransition_UpdateOncePerFrame(t *testing.T) {
var value float32 = .6
from := &MockScene{}
Expand Down

0 comments on commit 5d5f883

Please sign in to comment.