Skip to content

Commit fe8a2dd

Browse files
authored
Merge pull request #302 from logicalhan/set-tests
add test coverage to set.go
2 parents 0849a56 + 8c89a86 commit fe8a2dd

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

set/set_test.go

+35-2
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,17 @@ func TestStringSetEquals(t *testing.T) {
151151
if !a.Equal(b) {
152152
t.Errorf("Expected to be equal: %v vs %v", a, b)
153153
}
154-
154+
a = New[string]("1", "2", "3")
155+
b = New[string]("2", "1")
156+
if a.Equal(b) {
157+
t.Errorf("Expected to be not-equal: %v vs %v", a, b)
158+
}
155159
// It is a set; duplicates are ignored
160+
a = New[string]("1", "2")
156161
b = New[string]("2", "2", "1")
157162
if !a.Equal(b) {
158163
t.Errorf("Expected to be equal: %v vs %v", a, b)
159164
}
160-
161165
// Edge cases around empty sets / empty strings
162166
a = New[string]()
163167
b = New[string]()
@@ -369,3 +373,32 @@ func clearSetAndAdd[T ordered](s Set[T], a T) {
369373
s.Clear()
370374
s.Insert(a)
371375
}
376+
377+
func TestPopAny(t *testing.T) {
378+
a := New[string]("1", "2")
379+
_, popped := a.PopAny()
380+
if !popped {
381+
t.Errorf("got len(%d): wanted 1", a.Len())
382+
}
383+
_, popped = a.PopAny()
384+
if !popped {
385+
t.Errorf("got len(%d): wanted 0", a.Len())
386+
}
387+
zeroVal, popped := a.PopAny()
388+
if popped {
389+
t.Errorf("got len(%d): wanted 0", a.Len())
390+
}
391+
if zeroVal != "" {
392+
t.Errorf("should have gotten zero value when popping an empty set")
393+
}
394+
}
395+
396+
func TestClone(t *testing.T) {
397+
a := New[string]("1", "2")
398+
a.Insert("3")
399+
400+
got := a.Clone()
401+
if !reflect.DeepEqual(got, a) {
402+
t.Errorf("Expected to be equal: %v vs %v", got, a)
403+
}
404+
}

0 commit comments

Comments
 (0)