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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package memory
6
7 import (
8 "testing"
9
10 . "github.com/smartystreets/goconvey/convey"
11 )
12
13 // 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.
14 type kon struct{ k, o, n []byte }
15
16 var testCollisionCases = []struct {
17 name string
18 left, right []kv // inserts into left and right collections
19 expect []kon
20 }{
21 {
22 name: "nil",
23 },
24 {
25 name: "empty",
26 left: []kv{},
27 right: []kv{},
28 },
29 {
30 name: "all old",
31 left: []kv{
32 {cat(1), cat()},
33 {cat(0), cat()},
34 },
35 expect: []kon{
36 {cat(0), cat(), nil},
37 {cat(1), cat(), nil},
38 },
39 },
40 {
41 name: "all new",
42 right: []kv{
43 {cat(1), cat()},
44 {cat(0), cat()},
45 },
46 expect: []kon{
47 {cat(0), nil, cat()},
48 {cat(1), nil, cat()},
49 },
50 },
51 {
52 name: "new vals",
53 left: []kv{
54 {cat(1), cat("hi")},
55 {cat(0), cat("newb")},
56 },
57 right: []kv{
58 {cat(0), cat(2.5)},
59 {cat(1), cat(58)},
60 },
61 expect: []kon{
62 {cat(0), cat("newb"), cat(2.5)},
63 {cat(1), cat("hi"), cat(58)},
64 },
65 },
66 {
67 name: "mixed",
68 left: []kv{
69 {cat(1), cat("one")},
70 {cat(0), cat("hi")},
71 {cat(6), cat()},
72 {cat(3), cat(1.3)},
73 {cat(2), []byte("zoop")},
74 {cat(-1), cat("bob")},
75 },
76 right: []kv{
77 {cat(3), cat(1)},
78 {cat(1), cat(58)},
79 {cat(0), cat(2.5)},
80 {cat(4), cat(1337)},
81 {cat(2), cat("ski", 7)},
82 {cat(20), cat("nerd")},
83 },
84 expect: []kon{
85 {cat(-1), cat("bob"), nil},
86 {cat(0), cat("hi"), cat(2.5)},
87 {cat(1), cat("one"), cat(58)},
88 {cat(2), []byte("zoop"), cat("ski", 7)},
89 {cat(3), cat(1.3), cat(1)},
90 {cat(4), nil, cat(1337)},
91 {cat(6), cat(), nil},
92 {cat(20), nil, cat("nerd")},
93 },
94 },
95 }
96
97 func getFilledColl(s *memStore, fill []kv) *memCollection {
98 if fill == nil {
99 return nil
100 }
101 ret := s.MakePrivateCollection(nil)
102 for _, i := range fill {
103 ret.Set(i.k, i.v)
104 }
105 return ret
106 }
107
108 func TestCollision(t *testing.T) {
109 t.Parallel()
110
111 Convey("Test gkvCollide", t, func() {
112 s := newMemStore()
113 for _, tc := range testCollisionCases {
114 Convey(tc.name, func() {
115 left := getFilledColl(s, tc.left)
116 right := getFilledColl(s, tc.right)
117 i := 0
118 gkvCollide(left, right, func(k, o, n []byte) {
119 e := tc.expect[i]
120 So(k, ShouldResemble, e.k)
121 So(o, ShouldResemble, e.o)
122 So(n, ShouldResemble, e.n)
123 i++
124 })
125 So(i, ShouldEqual, len(tc.expect))
126 })
127 }
128 })
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698