Skip to content

Commit

Permalink
Merge pull request kubernetes#3631 from deads2k/deads-add-set-deleteall
Browse files Browse the repository at this point in the history
make StringSet.Delete accept multiple items
  • Loading branch information
smarterclayton committed Jan 20, 2015
2 parents 9192a4c + 5b8e38a commit 80d99b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/util/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ func (s StringSet) Insert(items ...string) {
}
}

// Delete removes item from the set.
func (s StringSet) Delete(item string) {
delete(s, item)
// Delete removes all items from the set.
func (s StringSet) Delete(items ...string) {
for _, item := range items {
delete(s, item)
}
}

// Has returns true iff item is contained in the set.
Expand Down
23 changes: 23 additions & 0 deletions pkg/util/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
s := NewStringSet("a", "b", "c")
if len(s) != 3 {
Expand Down

0 comments on commit 80d99b8

Please sign in to comment.