From 738fab12825b9859b22f8caf5b96878347afe80d Mon Sep 17 00:00:00 2001 From: "Jeong, Heon" Date: Mon, 10 Jun 2024 03:01:01 -0700 Subject: [PATCH] Add MockPlatform which mocks Platform interface (#6) * Add MockPlatform which mocks Platform interface It allows an unit test to control clocks. For usages, see https://github.com/noxworld-dev/opennox/pull/698 --------- Co-authored-by: Denys Smirnov --- noxtest/test_platform.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 noxtest/test_platform.go diff --git a/noxtest/test_platform.go b/noxtest/test_platform.go new file mode 100644 index 0000000..2c18fbe --- /dev/null +++ b/noxtest/test_platform.go @@ -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() { +}