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

Unified Diff: go/src/infra/gae/libs/wrapper/memory/gkvlite_utils_test.go

Issue 1160253002: Add initial Query generation, correctness checking and index generation. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: goimports Created 5 years, 7 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
Index: go/src/infra/gae/libs/wrapper/memory/gkvlite_utils_test.go
diff --git a/go/src/infra/gae/libs/wrapper/memory/gkvlite_utils_test.go b/go/src/infra/gae/libs/wrapper/memory/gkvlite_utils_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..4618d49e041069c3967ba9e5bee3cd29a319509b
--- /dev/null
+++ b/go/src/infra/gae/libs/wrapper/memory/gkvlite_utils_test.go
@@ -0,0 +1,129 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package memory
+
+import (
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+// key, old, new
M-A Ruel 2015/05/31 23:03:16 Then use these names. The goal is not to make the
iannucci 2015/05/31 23:31:33 Done.
+type kon struct{ k, o, n []byte }
+
+var testCollisionCases = []struct {
+ name string
+ left, right []kv // inserts into left and right collections
+ expect []kon
+}{
+ {
+ name: "nil",
+ },
+ {
+ name: "empty",
+ left: []kv{},
+ right: []kv{},
+ },
+ {
+ name: "all old",
+ left: []kv{
+ {cat(1), cat()},
+ {cat(0), cat()},
+ },
+ expect: []kon{
+ {cat(0), cat(), nil},
+ {cat(1), cat(), nil},
+ },
+ },
+ {
+ name: "all new",
+ right: []kv{
+ {cat(1), cat()},
+ {cat(0), cat()},
+ },
+ expect: []kon{
+ {cat(0), nil, cat()},
+ {cat(1), nil, cat()},
+ },
+ },
+ {
+ name: "new vals",
+ left: []kv{
+ {cat(1), cat("hi")},
+ {cat(0), cat("newb")},
+ },
+ right: []kv{
+ {cat(0), cat(2.5)},
+ {cat(1), cat(58)},
+ },
+ expect: []kon{
+ {cat(0), cat("newb"), cat(2.5)},
+ {cat(1), cat("hi"), cat(58)},
+ },
+ },
+ {
+ name: "mixed",
+ left: []kv{
+ {cat(1), cat("one")},
+ {cat(0), cat("hi")},
+ {cat(6), cat()},
+ {cat(3), cat(1.3)},
+ {cat(2), []byte("zoop")},
+ {cat(-1), cat("bob")},
+ },
+ right: []kv{
+ {cat(3), cat(1)},
+ {cat(1), cat(58)},
+ {cat(0), cat(2.5)},
+ {cat(4), cat(1337)},
+ {cat(2), cat("ski", 7)},
+ {cat(20), cat("nerd")},
+ },
+ expect: []kon{
+ {cat(-1), cat("bob"), nil},
+ {cat(0), cat("hi"), cat(2.5)},
+ {cat(1), cat("one"), cat(58)},
+ {cat(2), []byte("zoop"), cat("ski", 7)},
+ {cat(3), cat(1.3), cat(1)},
+ {cat(4), nil, cat(1337)},
+ {cat(6), cat(), nil},
+ {cat(20), nil, cat("nerd")},
+ },
+ },
+}
+
+func getFilledColl(s *memStore, fill []kv) *memCollection {
+ if fill == nil {
+ return nil
+ }
+ ret := s.MakePrivateCollection(nil)
+ for _, i := range fill {
+ ret.Set(i.k, i.v)
+ }
+ return ret
+}
+
+func TestCollision(t *testing.T) {
+ t.Parallel()
+
+ Convey("Test gkvCollide", t, func() {
+ s := newMemStore()
+ for _, tc := range testCollisionCases {
+ Convey(tc.name, func() {
+ left := getFilledColl(s, tc.left)
+ right := getFilledColl(s, tc.right)
+ i := 0
+ gkvCollide(left, right, func(k, o, n []byte) {
+ e := tc.expect[i]
+ So(k, ShouldResemble, e.k)
+ So(o, ShouldResemble, e.o)
+ So(n, ShouldResemble, e.n)
+ i++
+ })
+ So(i, ShouldEqual, len(tc.expect))
+ })
+ }
+ })
+}

Powered by Google App Engine
This is Rietveld 408576698