@@ -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+
9701034func Test_PowerSet (t * testing.T ) {
9711035 a := NewThreadUnsafeSet ()
9721036
0 commit comments