Renames HasAll to IsSuperset; HasAll uses slice.

For the pedants. HasAll is now called IsSuperset and
the new HasAll method takes a slice instead of a set.
This commit is contained in:
Danny Jones 2014-07-18 13:53:36 -07:00
parent 2d9bad95f8
commit 136c9e112c
3 changed files with 20 additions and 5 deletions

View File

@ -34,8 +34,7 @@ func TestValidateVolumes(t *testing.T) {
if len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
expectedSet := util.NewStringSet("abc", "123", "abc-123", "empty")
if len(names) != 4 || !names.HasAll(expectedSet) {
if len(names) != 4 || !names.HasAll("abc", "123", "abc-123", "empty") {
t.Errorf("wrong names result: %v", names)
}

View File

@ -51,7 +51,17 @@ func (s StringSet) Has(item string) bool {
}
// HasAll returns true iff all items are contained in the set.
func (s1 StringSet) HasAll(s2 StringSet) bool {
func (s StringSet) HasAll(items ...string) bool {
for _, item := range items {
if !s.Has(item) {
return false
}
}
return true
}
// IsSuperset returns true iff s1 is a superset of s2.
func (s1 StringSet) IsSuperset(s2 StringSet) bool {
for item, _ := range s2 {
if !s1.Has(item) {
return false

View File

@ -43,12 +43,18 @@ func TestStringSet(t *testing.T) {
t.Errorf("Unexpected contents: %#v", s)
}
s.Insert("a")
if s.HasAll("a","b","d") {
t.Errorf("Unexpected contents: %#v", s)
}
if !s.HasAll("a","b",) {
t.Errorf("Missing contents: %#v", s)
}
s2.Insert("a","b","d")
if s.HasAll(s2) {
if s.IsSuperset(s2) {
t.Errorf("Unexpected contents: %#v", s)
}
s2.Delete("d")
if !s.HasAll(s2) {
if !s.IsSuperset(s2) {
t.Errorf("Missing contents: %#v", s)
}
}