Skip to content

Commit

Permalink
Transition awareness tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Schutz committed Mar 1, 2024
1 parent 58c0132 commit c69298d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ type baseTransitionImplementation struct {

func (b *baseTransitionImplementation) Draw(screen *ebiten.Image) {}

type MockTransitionAwareScene struct {
MockScene
preTransitionCalled bool
postTransitionCalled bool
}

func (m *MockTransitionAwareScene) PreTransition(fromScene Scene[int]) int {
m.preTransitionCalled = true
return 0
}

func (m *MockTransitionAwareScene) PostTransition(state int, toScene Scene[int]) {
m.postTransitionCalled = true
}

func TestBaseTransition_Update(t *testing.T) {
from := &MockScene{}
to := &MockScene{}
Expand Down Expand Up @@ -72,6 +87,23 @@ func TestBaseTransition_Start(t *testing.T) {
assert.Equal(t, to, trans.toScene)
}

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

assert.True(t, from.preTransitionCalled)
assert.True(t, to.loadCalled)
assert.False(t, from.unloadCalled)
assert.False(t, to.postTransitionCalled)

trans.End()
assert.True(t, from.unloadCalled)
assert.True(t, to.postTransitionCalled)
}

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

0 comments on commit c69298d

Please sign in to comment.