-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer_test.go
More file actions
166 lines (134 loc) · 3.93 KB
/
timer_test.go
File metadata and controls
166 lines (134 loc) · 3.93 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package main
import (
"testing"
"time"
)
func TestTimerStateTransitions(t *testing.T) {
timer := Timer{
duration: 25 * time.Minute,
mode: "FOCUS",
state: StateRunning,
}
if timer.state != StateRunning {
t.Errorf("Expected initial state to be Running, got %v", timer.state)
}
timer.state = StatePaused
if timer.state != StatePaused {
t.Errorf("Expected state to be Paused, got %v", timer.state)
}
timer.state = StateStopped
if timer.state != StateStopped {
t.Errorf("Expected state to be Stopped, got %v", timer.state)
}
}
func TestSessionInitialization(t *testing.T) {
session := Session{
soundEnabled: true,
notificationsEnabled: true,
focusMinutes: 25,
shortBreakMinutes: 5,
longBreakMinutes: 15,
sessionsBeforeLongBreak: 4,
}
if session.focusMinutes != 25 {
t.Errorf("Expected focusMinutes to be 25, got %d", session.focusMinutes)
}
if session.shortBreakMinutes != 5 {
t.Errorf("Expected shortBreakMinutes to be 5, got %d", session.shortBreakMinutes)
}
if session.longBreakMinutes != 15 {
t.Errorf("Expected longBreakMinutes to be 15, got %d", session.longBreakMinutes)
}
if session.sessionsBeforeLongBreak != 4 {
t.Errorf("Expected sessionsBeforeLongBreak to be 4, got %d", session.sessionsBeforeLongBreak)
}
}
func TestSessionCounting(t *testing.T) {
session := Session{}
session.focusCount = 3
session.breakCount = 3
if session.focusCount != 3 {
t.Errorf("Expected focusCount to be 3, got %d", session.focusCount)
}
if session.breakCount != 3 {
t.Errorf("Expected breakCount to be 3, got %d", session.breakCount)
}
session.focusCount++
if session.focusCount != 4 {
t.Errorf("Expected focusCount to be 4, got %d", session.focusCount)
}
}
func TestLongBreakCalculation(t *testing.T) {
tests := []struct {
focusCount int
sessionsBeforeLongBreak int
expectedLongBreak bool
}{
{1, 4, false},
{2, 4, false},
{3, 4, false},
{4, 4, true},
{8, 4, true},
{3, 3, true},
}
for _, test := range tests {
result := test.focusCount%test.sessionsBeforeLongBreak == 0
if result != test.expectedLongBreak {
t.Errorf("focusCount=%d, sessionsBeforeLongBreak=%d: expected long break %v, got %v",
test.focusCount, test.sessionsBeforeLongBreak, test.expectedLongBreak, result)
}
}
}
func TestTimerDuration(t *testing.T) {
duration := 25 * time.Minute
timer := Timer{
duration: duration,
remaining: duration,
}
if timer.duration != duration {
t.Errorf("Expected duration to be %v, got %v", duration, timer.duration)
}
if timer.remaining != duration {
t.Errorf("Expected remaining to be %v, got %v", duration, timer.remaining)
}
}
func TestTotalFocusTime(t *testing.T) {
session := Session{}
focusDuration := 25 * time.Minute
session.focusCount = 3
session.totalFocusTime = focusDuration * time.Duration(session.focusCount)
expectedTotal := 75 * time.Minute
if session.totalFocusTime != expectedTotal {
t.Errorf("Expected totalFocusTime to be %v, got %v", expectedTotal, session.totalFocusTime)
}
}
func TestTotalBreakTime(t *testing.T) {
session := Session{}
breakDuration := 5 * time.Minute
session.breakCount = 2
session.totalBreakTime = breakDuration * time.Duration(session.breakCount)
expectedTotal := 10 * time.Minute
if session.totalBreakTime != expectedTotal {
t.Errorf("Expected totalBreakTime to be %v, got %v", expectedTotal, session.totalBreakTime)
}
}
func TestSoundNotificationSettings(t *testing.T) {
session := Session{
soundEnabled: false,
notificationsEnabled: false,
}
if session.soundEnabled {
t.Error("Expected soundEnabled to be false")
}
if session.notificationsEnabled {
t.Error("Expected notificationsEnabled to be false")
}
session.soundEnabled = true
session.notificationsEnabled = true
if !session.soundEnabled {
t.Error("Expected soundEnabled to be true")
}
if !session.notificationsEnabled {
t.Error("Expected notificationsEnabled to be true")
}
}