Skip to content

Commit 504e848

Browse files
committed
Adding tests
1 parent 8f7e665 commit 504e848

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

set_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,70 @@ func Test_IteratorStop(t *testing.T) {
967967
}
968968
}
969969

970+
func Test_PopSafe(t *testing.T) {
971+
a := NewSet()
972+
973+
a.Add("a")
974+
a.Add("b")
975+
a.Add("c")
976+
a.Add("d")
977+
978+
captureSet := NewSet()
979+
captureSet.Add(a.Pop())
980+
captureSet.Add(a.Pop())
981+
captureSet.Add(a.Pop())
982+
captureSet.Add(a.Pop())
983+
finalNil := a.Pop()
984+
985+
if captureSet.Cardinality() != 4 {
986+
t.Error("unexpected captureSet cardinality; should be 4")
987+
}
988+
989+
if a.Cardinality() != 0 {
990+
t.Error("unepxected a cardinality; should be zero")
991+
}
992+
993+
if !captureSet.Contains("c", "a", "d", "b") {
994+
t.Error("unexpected result set; should be a,b,c,d (any order is fine")
995+
}
996+
997+
if finalNil != nil {
998+
t.Error("when original set is empty, further pops should result in nil")
999+
}
1000+
}
1001+
1002+
func Test_PopUnsafe(t *testing.T) {
1003+
a := NewThreadUnsafeSet()
1004+
1005+
a.Add("a")
1006+
a.Add("b")
1007+
a.Add("c")
1008+
a.Add("d")
1009+
1010+
captureSet := NewThreadUnsafeSet()
1011+
captureSet.Add(a.Pop())
1012+
captureSet.Add(a.Pop())
1013+
captureSet.Add(a.Pop())
1014+
captureSet.Add(a.Pop())
1015+
finalNil := a.Pop()
1016+
1017+
if captureSet.Cardinality() != 4 {
1018+
t.Error("unexpected captureSet cardinality; should be 4")
1019+
}
1020+
1021+
if a.Cardinality() != 0 {
1022+
t.Error("unepxected a cardinality; should be zero")
1023+
}
1024+
1025+
if !captureSet.Contains("c", "a", "d", "b") {
1026+
t.Error("unexpected result set; should be a,b,c,d (any order is fine")
1027+
}
1028+
1029+
if finalNil != nil {
1030+
t.Error("when original set is empty, further pops should result in nil")
1031+
}
1032+
}
1033+
9701034
func Test_PowerSet(t *testing.T) {
9711035
a := NewThreadUnsafeSet()
9721036

threadsafe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (set *threadSafeSet) PowerSet() Set {
234234
func (set *threadSafeSet) Pop() interface{} {
235235
set.Lock()
236236
defer set.Unlock()
237-
return set.Pop()
237+
return set.s.Pop()
238238
}
239239

240240
func (set *threadSafeSet) CartesianProduct(other Set) Set {

0 commit comments

Comments
 (0)