File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,14 @@ type GitHubOrganization struct {
100
100
}
101
101
102
102
func NewAssignmentList (assignments []Assignment ) AssignmentList {
103
+ if len (assignments ) == 0 {
104
+ return AssignmentList {
105
+ Assignments : []Assignment {},
106
+ Classroom : Classroom {},
107
+ Count : 0 ,
108
+ }
109
+ }
110
+
103
111
classroom := assignments [0 ].Classroom
104
112
count := len (assignments )
105
113
@@ -111,6 +119,15 @@ func NewAssignmentList(assignments []Assignment) AssignmentList {
111
119
}
112
120
113
121
func NewAcceptedAssignmentList (assignments []AcceptedAssignment ) AcceptedAssignmentList {
122
+ if len (assignments ) == 0 {
123
+ return AcceptedAssignmentList {
124
+ AcceptedAssignments : []AcceptedAssignment {},
125
+ Classroom : Classroom {},
126
+ Assignment : Assignment {},
127
+ Count : 0 ,
128
+ }
129
+ }
130
+
114
131
classroom := assignments [0 ].Assignment .Classroom
115
132
assignment := assignments [0 ].Assignment
116
133
count := len (assignments )
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ func TestNewAssignmentList(t *testing.T) {
42
42
43
43
assert .Equal (t , assignmentList .Classroom .Name , "The Classroom" )
44
44
})
45
+
46
+ t .Run ("returns empty list when there are no assignments" , func (t * testing.T ) {
47
+ assignmentList := NewAssignmentList ([]Assignment {})
48
+ assert .Equal (t , assignmentList .Count , 0 )
49
+ })
45
50
}
46
51
47
52
func TestNewAcceptedAssignmentList (t * testing.T ) {
@@ -92,6 +97,11 @@ func TestNewAcceptedAssignmentList(t *testing.T) {
92
97
93
98
assert .Equal (t , assignmentList .Assignment .Title , "The Assignment" )
94
99
})
100
+
101
+ t .Run ("it returns an empty list when there are no accepted assignments" , func (t * testing.T ) {
102
+ assignmentList := NewAcceptedAssignmentList ([]AcceptedAssignment {})
103
+ assert .Equal (t , assignmentList .Count , 0 )
104
+ })
95
105
}
96
106
97
107
func TestAssignmentLists (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments