Skip to content

Commit 1f80db5

Browse files
committed
clean up section and course tests
1 parent 94133e7 commit 1f80db5

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

parser/courseParser.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"go.mongodb.org/mongo-driver/bson/primitive"
1313
)
1414

15-
var coursePrefixRexp *regexp.Regexp = utils.Regexpf(`^%s`, utils.R_SUBJ_COURSE_CAP)
16-
var contactRegexp *regexp.Regexp = regexp.MustCompile(`\(([0-9]+)-([0-9]+)\)\s+([SUFY]+)`)
15+
var (
16+
coursePrefixRexp *regexp.Regexp = utils.Regexpf(`^%s`, utils.R_SUBJ_COURSE_CAP)
17+
contactRegexp *regexp.Regexp = regexp.MustCompile(`\(([0-9]+)-([0-9]+)\)\s+([SUFY]+)`)
18+
)
1719

1820
func parseCourse(courseNum string, session schema.AcademicSession, rowInfo map[string]*goquery.Selection, classInfo map[string]string) *schema.Course {
1921
// Courses are internally keyed by their internal course number and the catalog year they're part of
@@ -37,7 +39,7 @@ func parseCourse(courseNum string, session schema.AcademicSession, rowInfo map[s
3739
return course
3840
}
3941

40-
// getCourse builds and returns a new course from the provided arguments, no global state is changed
42+
// no global state is changed
4143
func getCourse(courseNum string, session schema.AcademicSession, rowInfo map[string]*goquery.Selection, classInfo map[string]string) *schema.Course {
4244
CoursePrefix, CourseNumber := getPrefixAndNumber(classInfo)
4345

parser/courseParser_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ func TestGetPrefixAndCourseNum(t *testing.T) {
8787
prefix: "ENTP",
8888
number: "3301",
8989
},
90+
"Case_003": {
91+
classInfo: map[string]string{
92+
"Class Section:": "Garbage In, Garbage out",
93+
},
94+
prefix: "",
95+
number: "",
96+
},
97+
"Case_004": {
98+
classInfo: map[string]string{
99+
"Class Section:": "ENTP33S",
100+
},
101+
prefix: "",
102+
number: "",
103+
},
104+
"Case_005": {
105+
classInfo: map[string]string{
106+
"Class Section:": "",
107+
},
108+
prefix: "",
109+
number: "",
110+
},
90111
}
91112

92113
for name, testCase := range testCases {
@@ -100,6 +121,5 @@ func TestGetPrefixAndCourseNum(t *testing.T) {
100121
t.Errorf("expected %s got %s", testCase.number, number)
101122
}
102123
})
103-
104124
}
105125
}

parser/sectionParser_test.go

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ func TestGetInternalClassAndCourseNum(t *testing.T) {
1111

1212
for name, testCase := range testDataCache {
1313
t.Run(name, func(t *testing.T) {
14-
classNum, _ := getInternalClassAndCourseNum(testCase.ClassInfo)
14+
classNum, courseNum := getInternalClassAndCourseNum(testCase.ClassInfo)
1515
expectedClassNum := testCase.Section.Internal_class_number
16+
expectedCourseNumber := testCase.Course.Internal_course_number
1617

17-
diff := cmp.Diff(expectedClassNum, classNum)
18+
if classNum != expectedClassNum {
19+
t.Errorf("Class Number: expected %s got %s", expectedClassNum, classNum)
20+
}
1821

19-
if diff != "" {
20-
t.Errorf("Failed (-expected +got)\n %s", diff)
22+
if courseNum != expectedCourseNumber {
23+
t.Errorf("Class Number: expected %s got %s", expectedCourseNumber, courseNum)
2124
}
25+
2226
})
2327
}
2428
}
@@ -48,10 +52,8 @@ func TestGetSectionNumber(t *testing.T) {
4852
output := getSectionNumber(testCase.ClassInfo)
4953
expected := testCase.Section.Section_number
5054

51-
diff := cmp.Diff(expected, output)
52-
53-
if diff != "" {
54-
t.Errorf("Failed (-expected +got)\n %s", diff)
55+
if output != expected {
56+
t.Errorf("expected %s got %s", expected, output)
5557
}
5658
})
5759

@@ -66,20 +68,10 @@ func TestGetTeachingAssistants(t *testing.T) {
6668
output := getTeachingAssistants(testCase.RowInfo)
6769
expected := testCase.Section.Teaching_assistants
6870

69-
if len(output) != len(expected) {
70-
t.Errorf("expected %d assistants got %d", len(expected), len(output))
71-
return
72-
}
73-
74-
for i, assistant := range output {
75-
expectedAssistant := expected[i]
76-
77-
diff := cmp.Diff(expectedAssistant, assistant)
78-
79-
if diff != "" {
80-
t.Errorf("Failed (-expected +got)\n %s", diff)
81-
}
71+
diff := cmp.Diff(expected, output)
8272

73+
if diff != "" {
74+
t.Errorf("Failed (-expected +got)\n %s", diff)
8375
}
8476
})
8577
}
@@ -93,10 +85,8 @@ func TestGetInstructionMode(t *testing.T) {
9385
output := getInstructionMode(testCase.ClassInfo)
9486
expected := testCase.Section.Instruction_mode
9587

96-
diff := cmp.Diff(expected, output)
97-
98-
if diff != "" {
99-
t.Errorf("Failed (-expected +got)\n %s", diff)
88+
if output != expected {
89+
t.Errorf("expected %s got %s", expected, output)
10090
}
10191
})
10292

@@ -111,19 +101,10 @@ func TestGetMeetings(t *testing.T) {
111101
output := getMeetings(testCase.RowInfo)
112102
expected := testCase.Section.Meetings
113103

114-
if len(output) != len(expected) {
115-
t.Errorf("expected %d meetings got %d", len(expected), len(output))
116-
return
117-
}
118-
119-
for i, meeting := range output {
120-
expectedMeeting := expected[i]
121-
122-
diff := cmp.Diff(meeting, expectedMeeting)
104+
diff := cmp.Diff(expected, output)
123105

124-
if diff != "" {
125-
t.Errorf("Failed (-expected +got)\n %s", diff)
126-
}
106+
if diff != "" {
107+
t.Errorf("Failed (-expected +got)\n %s", diff)
127108
}
128109
})
129110
}
@@ -154,10 +135,8 @@ func TestGetSyllabusUri(t *testing.T) {
154135
output := getSyllabusUri(testCase.RowInfo)
155136
expected := testCase.Section.Syllabus_uri
156137

157-
diff := cmp.Diff(expected, output)
158-
159-
if diff != "" {
160-
t.Errorf("Failed (-expected +got)\n %s", diff)
138+
if output != expected {
139+
t.Errorf("expected %s got %s", expected, output)
161140
}
162141
})
163142

0 commit comments

Comments
 (0)