Skip to content

Commit

Permalink
Merge pull request #42 from bcwaldon/values
Browse files Browse the repository at this point in the history
feat(set): Add set.Values() method
  • Loading branch information
bcwaldon committed Apr 2, 2014
2 parents 9d69345 + 68b6a03 commit 8514b9f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dbus/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (s *set) Length() (int) {
return len(s.data)
}

func (s *set) Values() (values []string) {
for val, _ := range s.data {
values = append(values, val)
}
return
}

func newSet() (*set) {
return &set{make(map[string] bool)}
}
13 changes: 13 additions & 0 deletions dbus/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ func TestBasicSetActions(t *testing.T) {
t.Fatal("set should contain 'foo'")
}

v := s.Values()
if len(v) != 1 {
t.Fatal("set.Values did not report correct number of values")
}
if v[0] != "foo" {
t.Fatal("set.Values did not report value")
}

s.Remove("foo")

if s.Contains("foo") {
t.Fatal("set should not contain 'foo'")
}

v = s.Values()
if len(v) != 0 {
t.Fatal("set.Values did not report correct number of values")
}
}

0 comments on commit 8514b9f

Please sign in to comment.