-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming_test.go
39 lines (34 loc) · 1.54 KB
/
timing_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package consolizer
import (
"github.com/stretchr/testify/assert"
"github.com/supercom32/consolizer/internal/memory"
"testing"
)
func TestTimerFunctionality(test *testing.T) {
memory.InitializeTimerMemory()
timerEntry := AddTimer(3000, true)
SleepInMilliseconds(1000)
assert.Equalf(test, timerEntry.IsExpired(), false, "The timer was flagged as expired when not enough time has elapsed.")
SleepInMilliseconds(2500)
assert.Equalf(test, timerEntry.IsExpired(), true, "The timer was not flagged as expired when more time has elapsed.")
}
func TestSetTimerFunctionality(test *testing.T) {
memory.InitializeTimerMemory()
timerEntry := AddTimer(9000, false)
timerEntry.SetTimer(3000, true)
SleepInSeconds(1)
assert.Equalf(test, timerEntry.IsExpired(), false, "The timer was flagged as expired when not enough time has elapsed.")
Sleep(2500)
assert.Equalf(test, timerEntry.IsExpired(), true, "The timer was not flagged as expired when more time has elapsed.")
}
func TestResetTimerFunctionality(test *testing.T) {
memory.InitializeTimerMemory()
timerEntry := AddTimer(1000, true)
SleepInMilliseconds(1500)
assert.Equalf(test, true, timerEntry.IsExpired(), "The initial timer was not flagged as expired when more time has elapsed.")
timerEntry.Start()
SleepInMilliseconds(500)
assert.Equalf(test, false, timerEntry.IsExpired(), "The reset timer was flagged as expired when not enough time has elapsed.")
SleepInMilliseconds(1000)
assert.Equalf(test, true, timerEntry.IsExpired(), "The reset timer was not flagged as expired when more time has elapsed.")
}