-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer_test.go
116 lines (101 loc) · 2.83 KB
/
timer_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"testing"
"time"
)
func TestNewTimer(t *testing.T) {
tmrUp, err := NewTimer(CountUp, "Test Up Timer", "test_up", 0, time.Duration(0))
if err != nil || tmrUp == nil {
t.Errorf("failed to create up timer: %s", err)
}
if tmrUp.totalSecs != 0 {
t.Errorf("up timer totalSecs want 0 got %f", tmrUp.totalSecs)
}
d := time.Duration(1 * time.Minute)
tmrDown, err := NewTimer(CountDown, "Test Down Timer", "test_down", 1, d)
if err != nil || tmrDown == nil {
t.Errorf("failed to create down timer: %s", err)
}
if tmrDown.totalSecs != d.Seconds() {
t.Errorf("down timer totalSecs want %f got %f", d.Seconds(), tmrDown.totalSecs)
}
}
func TestTimerUpdate(t *testing.T) {
tmr, err := NewTimer(CountUp, "Test Timer", "test", 0, time.Duration(0))
if err != nil || tmr == nil {
t.Errorf("failed to create timer: %s", err)
}
d, _ := time.ParseDuration("1s")
cur := tmr.totalSecs
tmr.update(d)
if tmr.totalSecs != cur+d.Seconds() {
t.Errorf("update wanted %f, got %f", cur+d.Seconds(), tmr.totalSecs)
}
}
/*
func TestTimerStart(t *testing.T) {
tmr, err := NewTimer(CountUp, "Test Timer", "test", 0, time.Duration(0))
if err != nil || tmr == nil {
t.Errorf("failed to create timer: %s", err)
}
tmr.Start()
time.Sleep(100 * time.Millisecond)
if !tmr.running {
t.Errorf("failed to start timer")
}
}
func TestTimerStop(t *testing.T) {
tmr, err := NewTimer(CountUp, "Test Timer", "test", 0, time.Duration(0))
if err != nil || tmr == nil {
t.Errorf("failed to create timer: %s", err)
}
tmr.Start()
time.Sleep(100 * time.Millisecond)
tmr.Stop()
if tmr.running {
t.Errorf("failed to stop timer")
}
}
*/
func TestTimerHMS(t *testing.T) {
tmr, err := NewTimer(CountUp, "Test Timer", "test", 0, time.Duration(0))
if err != nil || tmr == nil {
t.Errorf("failed to create timer: %s", err)
}
tmr.totalSecs = 60.0
tmr.set = true
hms := tmr.HMS()
if hms != "00:01:00" {
t.Errorf("HMS want 00:01:00, got %s", hms)
}
}
func TestTimerHMSIndicator(t *testing.T) {
tmr, err := NewTimer(CountDown, "Test Timer", "test", 0, time.Duration(1*time.Minute))
if err != nil || tmr == nil {
t.Errorf("failed to create timer: %s", err)
}
tmr.set = true
hmsIndicator := tmr.HMSIndicator()
if hmsIndicator != "-" {
t.Errorf("want indicator -, got %s", hmsIndicator)
}
tmr.totalSecs = -60.0
hmsIndicator = tmr.HMSIndicator()
if hmsIndicator != "+" {
t.Errorf("want indicator +, got %s", hmsIndicator)
}
tmr.timerType = CountUp
hmsIndicator = tmr.HMSIndicator()
if hmsIndicator != "-" {
t.Errorf("want indicator -, got %s", hmsIndicator)
}
}
func TestTimerOver(t *testing.T) {
tmr, err := NewTimer(CountDown, "Test Timer", "test", 0, time.Duration(-1*time.Minute))
if err != nil || tmr == nil {
t.Errorf("failed to create timer: %s", err)
}
if !tmr.Over() {
t.Error("timer over not set when it should be")
}
}