forked from UTDNebula/api-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsectionParser_test.go
More file actions
273 lines (216 loc) · 5.28 KB
/
sectionParser_test.go
File metadata and controls
273 lines (216 loc) · 5.28 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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package parser
import (
"fmt"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
func TestGetInternalClassAndCourseNum(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
classNum, courseNum := getInternalClassAndCourseNum(testCase.ClassInfo)
expectedClassNum := testCase.Section.Internal_class_number
expectedCourseNumber := testCase.Course.Internal_course_number
if classNum != expectedClassNum {
t.Errorf("Class Number: expected %s got %s", expectedClassNum, classNum)
}
if courseNum != expectedCourseNumber {
t.Errorf("Class Number: expected %s got %s", expectedCourseNumber, courseNum)
}
})
}
fails := []map[string]string{
{
"Class Section:": "ENTP33S",
},
{
"Class Section:": "",
},
{
"Class Section:": "Garbage In, Garbage out",
},
}
for i, fail := range fails {
name := fmt.Sprintf("case_%03d", i+len(testData))
t.Run(name, func(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r == nil {
t.Errorf("expected panic for input %s but none occurred", fail)
}
}()
getInternalClassAndCourseNum(fail)
})
}
}
func TestGetAcademicSession(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getAcademicSession(testCase.RowInfo)
expected := testCase.Section.Academic_session
diff := cmp.Diff(expected, output)
if diff != "" {
t.Errorf("Failed (-expected +got)\n %s", diff)
}
})
}
}
func TestGetSectionNumber(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getSectionNumber(testCase.ClassInfo)
expected := testCase.Section.Section_number
if output != expected {
t.Errorf("expected %s got %s", expected, output)
}
})
}
fails := []map[string]string{
{
"Class Section:": "ENTP33S",
},
{
"Class Section:": "",
},
{
"Class Section:": "Garbage In, Garbage out",
},
}
for i, fail := range fails {
name := fmt.Sprintf("case_%03d", i+len(testData))
t.Run(name, func(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r == nil {
t.Errorf("expected panic for input %s but none occurred", fail)
}
}()
getSectionNumber(fail)
})
}
}
func TestGetTeachingAssistants(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getTeachingAssistants(testCase.RowInfo)
expected := testCase.Section.Teaching_assistants
diff := cmp.Diff(expected, output)
if diff != "" {
t.Errorf("Failed (-expected +got)\n %s", diff)
}
})
}
}
func TestGetInstructionMode(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getInstructionMode(testCase.ClassInfo)
expected := testCase.Section.Instruction_mode
if output != expected {
t.Errorf("expected %s got %s", expected, output)
}
})
}
}
func TestGetMeetings(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getMeetings(testCase.RowInfo)
expected := testCase.Section.Meetings
diff := cmp.Diff(expected, output)
if diff != "" {
t.Errorf("Failed (-expected +got)\n %s", diff)
}
})
}
}
func TestGetCoreFlags(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getCoreFlags(testCase.RowInfo)
expected := testCase.Section.Core_flags
diff := cmp.Diff(expected, output)
if diff != "" {
t.Errorf("Failed (-expected +got)\n %s", diff)
}
})
}
}
func TestGetSyllabusUri(t *testing.T) {
t.Parallel()
for name, testCase := range testData {
t.Run(name, func(t *testing.T) {
t.Parallel()
output := getSyllabusUri(testCase.RowInfo)
expected := testCase.Section.Syllabus_uri
if output != expected {
t.Errorf("expected %s got %s", expected, output)
}
})
}
}
func TestParseTimeOrPanic(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
Input string
Expected time.Time
Panic bool
}{
"Case_001": {
Input: "January 2, 2006",
Expected: time.Date(2006, time.January, 2, 0, 0, 0, 0, timeLocation),
Panic: false,
},
"Case_002": {
Input: "March 15, 2020",
Expected: time.Date(2020, time.March, 15, 0, 0, 0, 0, timeLocation),
Panic: false,
},
"Case_003": {
Input: "15 March, 2020", // wrong format
Panic: true,
},
"Case_004": {
Input: "Not a date", // clearly wrong
Panic: true,
},
"Case_005": {
Input: "", // empty input
Panic: true,
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()
defer func() {
if r := recover(); r != nil {
if !testCase.Panic {
t.Errorf("unexpected panic for input %q: %v", testCase.Input, r)
}
} else {
if testCase.Panic {
t.Errorf("expected panic for input %q but none occurred", testCase.Input)
}
}
}()
got := parseTimeOrPanic(testCase.Input)
if !testCase.Panic && !got.Equal(testCase.Expected) {
t.Errorf("expected %v, got %v", testCase.Expected, got)
}
})
}
}