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

Side by Side Diff: impl/memory/gkvlite_utils_test.go

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

Powered by Google App Engine
This is Rietveld 408576698