diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2016-12-28 16:26:56 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-28 16:26:56 -0700 |
commit | a705895fdad108f053eae7ee011ed94a0541ee13 (patch) | |
tree | 5b0e75f887b17a32da522a0716b09b701d46d309 | |
parent | Clean up timeout tests. (diff) | |
parent | Ensure that keys generated by testing/quick are unique (diff) | |
download | dedo-a705895fdad108f053eae7ee011ed94a0541ee13.tar.gz dedo-a705895fdad108f053eae7ee011ed94a0541ee13.tar.xz |
Merge pull request #642 from josharian/fix629
Ensure that keys generated by testing/quick are unique
-rw-r--r-- | quick_test.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/quick_test.go b/quick_test.go index 4da5817..9e27792 100644 --- a/quick_test.go +++ b/quick_test.go @@ -50,9 +50,17 @@ func (t testdata) Less(i, j int) bool { return bytes.Compare(t[i].Key, t[j].Key) func (t testdata) Generate(rand *rand.Rand, size int) reflect.Value { n := rand.Intn(qmaxitems-1) + 1 items := make(testdata, n) + used := make(map[string]bool) for i := 0; i < n; i++ { item := &items[i] - item.Key = randByteSlice(rand, 1, qmaxksize) + // Ensure that keys are unique by looping until we find one that we have not already used. + for { + item.Key = randByteSlice(rand, 1, qmaxksize) + if !used[string(item.Key)] { + used[string(item.Key)] = true + break + } + } item.Value = randByteSlice(rand, 0, qmaxvsize) } return reflect.ValueOf(items) |