| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 . "github.com/smartystreets/goconvey/convey" | 10 . "github.com/smartystreets/goconvey/convey" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 {cat(1), cat("one"), cat(58)}, | 88 {cat(1), cat("one"), cat(58)}, |
| 89 {cat(2), []byte("zoop"), cat("ski", 7)}, | 89 {cat(2), []byte("zoop"), cat("ski", 7)}, |
| 90 {cat(3), cat(1.3), cat(1)}, | 90 {cat(3), cat(1.3), cat(1)}, |
| 91 {cat(4), nil, cat(1337)}, | 91 {cat(4), nil, cat(1337)}, |
| 92 {cat(6), cat(), nil}, | 92 {cat(6), cat(), nil}, |
| 93 {cat(20), nil, cat("nerd")}, | 93 {cat(20), nil, cat("nerd")}, |
| 94 }, | 94 }, |
| 95 }, | 95 }, |
| 96 } | 96 } |
| 97 | 97 |
| 98 func getFilledColl(s *memStore, fill []kv) *memCollection { | 98 func getFilledColl(fill []kv) memCollection { |
| 99 if fill == nil { | 99 if fill == nil { |
| 100 return nil | 100 return nil |
| 101 } | 101 } |
| 102 » ret := s.MakePrivateCollection(nil) | 102 » store := newMemStore() |
| 103 » ret := store.GetOrCreateCollection("") |
| 103 for _, i := range fill { | 104 for _, i := range fill { |
| 104 ret.Set(i.k, i.v) | 105 ret.Set(i.k, i.v) |
| 105 } | 106 } |
| 106 » return ret | 107 » return store.Snapshot().GetCollection("") |
| 107 } | 108 } |
| 108 | 109 |
| 109 func TestCollision(t *testing.T) { | 110 func TestCollision(t *testing.T) { |
| 110 t.Parallel() | 111 t.Parallel() |
| 111 | 112 |
| 112 Convey("Test gkvCollide", t, func() { | 113 Convey("Test gkvCollide", t, func() { |
| 113 s := newMemStore() | |
| 114 for _, tc := range testCollisionCases { | 114 for _, tc := range testCollisionCases { |
| 115 Convey(tc.name, func() { | 115 Convey(tc.name, func() { |
| 116 » » » » left := getFilledColl(s, tc.left) | 116 » » » » left := getFilledColl(tc.left) |
| 117 » » » » right := getFilledColl(s, tc.right) | 117 » » » » right := getFilledColl(tc.right) |
| 118 i := 0 | 118 i := 0 |
| 119 gkvCollide(left, right, func(key, left, right []
byte) { | 119 gkvCollide(left, right, func(key, left, right []
byte) { |
| 120 e := tc.expect[i] | 120 e := tc.expect[i] |
| 121 So(key, ShouldResemble, e.key) | 121 So(key, ShouldResemble, e.key) |
| 122 So(left, ShouldResemble, e.left) | 122 So(left, ShouldResemble, e.left) |
| 123 So(right, ShouldResemble, e.right) | 123 So(right, ShouldResemble, e.right) |
| 124 i++ | 124 i++ |
| 125 }) | 125 }) |
| 126 So(i, ShouldEqual, len(tc.expect)) | 126 So(i, ShouldEqual, len(tc.expect)) |
| 127 }) | 127 }) |
| 128 } | 128 } |
| 129 }) | 129 }) |
| 130 } | 130 } |
| OLD | NEW |