1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/hanchuanchuan-goInception

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
mvmap_test.go 2.1 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
hanchuanchuan Отправлено 6 лет назад 0f09d27
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package mvmap
import (
"bytes"
"encoding/binary"
"fmt"
"hash/fnv"
"testing"
)
func TestMVMap(t *testing.T) {
m := NewMVMap()
var vals [][]byte
m.Put([]byte("abc"), []byte("abc1"))
m.Put([]byte("abc"), []byte("abc2"))
m.Put([]byte("def"), []byte("def1"))
m.Put([]byte("def"), []byte("def2"))
vals = m.Get([]byte("abc"), vals[:0])
if fmt.Sprintf("%s", vals) != "[abc1 abc2]" {
t.FailNow()
}
vals = m.Get([]byte("def"), vals[:0])
if fmt.Sprintf("%s", vals) != "[def1 def2]" {
t.FailNow()
}
if m.Len() != 4 {
t.FailNow()
}
results := []string{"abc abc1", "abc abc2", "def def1", "def def2"}
it := m.NewIterator()
for i := 0; i < 4; i++ {
key, val := it.Next()
if fmt.Sprintf("%s %s", key, val) != results[i] {
t.FailNow()
}
}
key, val := it.Next()
if key != nil || val != nil {
t.FailNow()
}
}
func BenchmarkMVMapPut(b *testing.B) {
m := NewMVMap()
buffer := make([]byte, 8)
for i := 0; i < b.N; i++ {
binary.BigEndian.PutUint64(buffer, uint64(i))
m.Put(buffer, buffer)
}
}
func BenchmarkMVMapGet(b *testing.B) {
m := NewMVMap()
buffer := make([]byte, 8)
for i := 0; i < b.N; i++ {
binary.BigEndian.PutUint64(buffer, uint64(i))
m.Put(buffer, buffer)
}
val := make([][]byte, 0, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
binary.BigEndian.PutUint64(buffer, uint64(i))
val = m.Get(buffer, val[:0])
if len(val) != 1 || bytes.Compare(val[0], buffer) != 0 {
b.FailNow()
}
}
}
func TestFNVHash(t *testing.T) {
b := []byte{0xcb, 0xf2, 0x9c, 0xe4, 0x84, 0x22, 0x23, 0x25}
sum1 := fnvHash64(b)
hash := fnv.New64()
hash.Reset()
hash.Write(b)
sum2 := hash.Sum64()
if sum1 != sum2 {
t.FailNow()
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/hanchuanchuan-goInception.git
git@gitlife.ru:oschina-mirror/hanchuanchuan-goInception.git
oschina-mirror
hanchuanchuan-goInception
hanchuanchuan-goInception
v1.2.3