Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Unified Diff: common/data/treapstore/store_test.go

Issue 2616303002: treapstore: Add Collection.VisitItemsAscend. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/data/treapstore/store.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/data/treapstore/store_test.go
diff --git a/common/data/treapstore/store_test.go b/common/data/treapstore/store_test.go
index 075470b8b233633dc78aa26bcd828c698f2c2989..99057867d9e6c35eca5dce1d8223df5911bb6dee 100644
--- a/common/data/treapstore/store_test.go
+++ b/common/data/treapstore/store_test.go
@@ -25,6 +25,15 @@ func putMulti(c *Collection, vs ...string) {
}
}
+func visitAll(c *Collection, pivot string) []string {
+ res := []string{}
+ c.VisitAscend(pivot, func(v gtreap.Item) bool {
+ res = append(res, v.(string))
+ return true
+ })
+ return res
+}
+
func iterAll(it *gtreap.Iterator) []string {
all := []string{}
for {
@@ -36,6 +45,31 @@ func iterAll(it *gtreap.Iterator) []string {
}
}
+func shouldHaveKeys(actual interface{}, expected ...interface{}) string {
+ c := actual.(*Collection)
+
+ // expected can either be a single []string or a series of strings.
+ var keys []string
+ var ok bool
+ if len(expected) == 1 {
+ keys, ok = expected[0].([]string)
+ }
+ if !ok {
+ keys = make([]string, len(expected))
+ for i, v := range expected {
+ keys[i] = v.(string)
+ }
+ }
+
+ if err := ShouldResemble(iterAll(c.Iterator("")), keys); err != "" {
+ return fmt.Sprintf("failed via iterator: %s", err)
+ }
+ if err := ShouldResemble(visitAll(c, ""), keys); err != "" {
+ return fmt.Sprintf("failed via visit: %s", err)
+ }
+ return ""
+}
+
func TestStore(t *testing.T) {
t.Parallel()
@@ -46,7 +80,7 @@ func TestStore(t *testing.T) {
Convey(`When empty`, func() {
checkEmpty := func(c *Collection) {
So(c.Get("foo"), ShouldBeNil)
- So(iterAll(c.Iterator("")), ShouldResemble, []string{})
+ So(c, shouldHaveKeys)
}
// Check the basic Store.
@@ -68,7 +102,7 @@ func TestStore(t *testing.T) {
So(coll.Get(k), ShouldEqual, k)
}
- So(iterAll(coll.Iterator("")), ShouldResemble, keys)
+ So(coll, shouldHaveKeys, keys)
for i, k := range keys {
So(iterAll(coll.Iterator(k)), ShouldResemble, keys[i:])
So(iterAll(coll.Iterator(k+"1")), ShouldResemble, keys[i+1:])
« no previous file with comments | « common/data/treapstore/store.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698