Commit 80d99b8d authored by Clayton Coleman's avatar Clayton Coleman

Merge pull request #3631 from deads2k/deads-add-set-deleteall

make StringSet.Delete accept multiple items
parents 9192a4ce 5b8e38a6
...@@ -39,9 +39,11 @@ func (s StringSet) Insert(items ...string) { ...@@ -39,9 +39,11 @@ func (s StringSet) Insert(items ...string) {
} }
} }
// Delete removes item from the set. // Delete removes all items from the set.
func (s StringSet) Delete(item string) { func (s StringSet) Delete(items ...string) {
delete(s, item) for _, item := range items {
delete(s, item)
}
} }
// Has returns true iff item is contained in the set. // Has returns true iff item is contained in the set.
......
...@@ -59,6 +59,29 @@ func TestStringSet(t *testing.T) { ...@@ -59,6 +59,29 @@ func TestStringSet(t *testing.T) {
} }
} }
func TestStringSetDeleteMultiples(t *testing.T) {
s := StringSet{}
s.Insert("a", "b", "c")
if len(s) != 3 {
t.Errorf("Expected len=3: %d", len(s))
}
s.Delete("a", "c")
if len(s) != 1 {
t.Errorf("Expected len=1: %d", len(s))
}
if s.Has("a") {
t.Errorf("Unexpected contents: %#v", s)
}
if s.Has("c") {
t.Errorf("Unexpected contents: %#v", s)
}
if !s.Has("b") {
t.Errorf("Missing contents: %#v", s)
}
}
func TestNewStringSet(t *testing.T) { func TestNewStringSet(t *testing.T) {
s := NewStringSet("a", "b", "c") s := NewStringSet("a", "b", "c")
if len(s) != 3 { if len(s) != 3 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment