Skip to content

Commit

Permalink
Add MockPlatform which mocks Platform interface (#6)
Browse files Browse the repository at this point in the history
* Add MockPlatform which mocks Platform interface

It allows an unit test to control clocks.

For usages, see noxworld-dev/opennox#698

---------

Co-authored-by: Denys Smirnov <dennwc@protonmail.com>
  • Loading branch information
blmarket and dennwc committed Jun 10, 2024
1 parent 67a1e62 commit 738fab1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions noxtest/test_platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package noxtest

import (
"time"
)

// MockPlatform is a mock Platform implementation to allow test using ticks
type MockPlatform struct {
T time.Duration
}

func (p *MockPlatform) Ticks() time.Duration {
return p.T
}

func (p *MockPlatform) Sleep(dt time.Duration) {
p.T += dt
}

func (p *MockPlatform) TimeSeed() int64 {
return 0
}

func (p *MockPlatform) RandInt() int {
return 0
}

func (p *MockPlatform) RandSeed(seed int64) {
}

func (p *MockPlatform) RandSeedTime() {
}

0 comments on commit 738fab1

Please sign in to comment.