-
Notifications
You must be signed in to change notification settings - Fork 0
/
totals_test.go
226 lines (209 loc) · 4.63 KB
/
totals_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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package main
import (
"os"
"path/filepath"
"testing"
"time"
)
func TestNewTotals(t *testing.T) {
t.Parallel()
totals := newTotals("blah")
if totals.notesPath != "blah" {
t.Error("notes path is incorrect")
}
}
func newTestTotals() totals {
return totals{
sowIndex: 4,
notesPath: "doesnt/matter",
current: "something fun",
days: []map[string]int{
map[string]int{
"cat1": 4,
"cat2, one": 8,
"cat2, two": 12,
},
map[string]int{
"cat1": 4,
"cat2, one": 16,
"cat2, two": 24,
},
map[string]int{
"cat1": 4,
"cat4, one": 32,
"cat3, two": 48,
},
map[string]int{
"cat1": 4,
"cat8, one": 8,
"cat0, two": 12,
},
map[string]int{
"cat9": 4,
"cat9, one": 8,
"cat9, two": 12,
},
map[string]int{
"cat1": 4,
"cat2, one": 8,
"cat2, two": 12,
},
map[string]int{
"cat1": 4,
"cat8, one": 8,
"cat0, two": 12,
},
map[string]int{
"cat9": 4,
"cat9, one": 8,
"cat9, two": 12,
},
map[string]int{
"cat1": 4,
"cat2, one": 8,
"cat2, two": 12,
},
map[string]int{
"cat1": 4,
"cat8, one": 8,
"cat0, two": 12,
},
map[string]int{
"cat9": 4,
"cat9, one": 8,
"cat9, two": 12,
},
map[string]int{
"cat1": 4,
"cat2, one": 8,
"cat2, two": 12,
},
map[string]int{
"cat1": 4,
"cat8, one": 8,
"cat0, two": 12,
},
map[string]int{
"cat9": 4,
"cat9, one": 8,
"cat9, two": 12,
},
map[string]int{
"cat1": 4,
"cat2, one": 8,
"cat2, two": 12,
},
},
}
}
func TestOneDayTotal(t *testing.T) {
t.Parallel()
totals := newTestTotals()
if totals.nDayTotalMinutes(1) != 24 {
t.Error("day total is incorrect")
}
}
func TestFiveDayTotal(t *testing.T) {
t.Parallel()
totals := newTestTotals()
if totals.nDayTotalMinutes(5) != 200 {
t.Error("five day total is incorrect")
}
}
func TestFifteenDayTotal(t *testing.T) {
t.Parallel()
totals := newTestTotals()
if totals.nDayTotalMinutes(15) != 440 {
t.Error("fifteen day total is incorrect")
}
}
func TestOneDayThemeTotalMinutes(t *testing.T) {
t.Parallel()
totals := newTestTotals()
wtt := totals.nDayThemeTotalMinutes(1)
if wtt["cat1"] != 4 {
t.Error("day theme totals cat1 is incorrect")
}
if wtt["cat2"] != 20 {
t.Error("day theme totals cat2 is incorrect")
}
}
func TestFiveDayThemeTotalMinutes(t *testing.T) {
t.Parallel()
totals := newTestTotals()
fivedaytt := totals.nDayThemeTotalMinutes(5)
if fivedaytt["cat1"] != 16 {
t.Error("five day theme totals cat1 is incorrect")
}
if fivedaytt["cat2"] != 60 {
t.Error("five day theme totals cat2 is incorrect")
}
if fivedaytt["cat9"] != 24 {
t.Error("five day theme totals cat9 is incorrect")
}
}
func TestFifteenDayThemeTotalMinutes(t *testing.T) {
t.Parallel()
totals := newTestTotals()
fifteendaytt := totals.nDayThemeTotalMinutes(15)
if fifteendaytt["cat1"] != 44 {
t.Error("fifteen day theme totals cat1 is incorrect")
}
if fifteendaytt["cat2"] != 140 {
t.Error("fifteen day theme totals cat2 is incorrect")
}
if fifteendaytt["cat9"] != 96 {
t.Error("fifteen day theme totals cat9 is incorrect")
}
}
func TestWeekTotalMinutes(t *testing.T) {
t.Parallel()
totals := newTestTotals()
if totals.weekTotalMinutes() != 200 {
t.Error("week total is incorrect")
}
}
func TestOneDayThemePercent(t *testing.T) {
t.Parallel()
totals := newTestTotals()
if totals.nDayThemePercent(1, "cat1") != 16.666666666666664 {
t.Error("day theme percent cat1 is incorrect")
}
if totals.nDayThemePercent(1, "cat2") != 83.33333333333334 {
t.Error("day theme percent cat2 is incorrect")
}
}
func TestCalculatePathError(t *testing.T) {
t.Parallel()
totals := newTotals("does/not/exist")
if err := totals.calculate(time.Now(), 15); err == nil {
t.Error("calculate should have errored")
}
}
func TestCalculateSkipDirs(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
err := createTestNoteFiles(tempDir, nil)
if err != nil {
t.Fatal(err.Error())
}
totals := newTotals(tempDir)
// TODO probably make sure actual files in
// these dirs are not parsed?
os.Mkdir(filepath.Join(tempDir, ".git"), 0777)
os.Mkdir(filepath.Join(tempDir, "2020"), 0777)
os.Mkdir(filepath.Join(tempDir, "2021"), 0777)
_ = totals.calculate(time.Now(), 15)
}
func TestCalculate(t *testing.T) {
t.Parallel()
tempDir := t.TempDir()
err := createTestNoteFiles(tempDir, nil)
if err != nil {
t.Fatal(err.Error())
}
totals := newTotals(tempDir)
// when the test files start
then := time.Date(2021, time.October, 5, 12, 0, 0, 0, time.UTC)
_ = totals.calculate(then, 15)
}