gf/encoding/ghash/ghash_z_unit_basic_test.go

141 lines
2.5 KiB
Go
Raw Normal View History

2019-06-19 09:06:52 +08:00
package ghash_test
import (
"testing"
2019-07-29 21:01:19 +08:00
"github.com/gogf/gf/encoding/ghash"
"github.com/gogf/gf/test/gtest"
2019-06-19 09:06:52 +08:00
)
var (
strBasic = []byte("This is the test string for hash.")
)
func Test_BKDRHash(t *testing.T) {
var x uint32 = 200645773
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.BKDRHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_BKDRHash64(t *testing.T) {
var x uint64 = 4214762819217104013
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.BKDRHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_SDBMHash(t *testing.T) {
var x uint32 = 1069170245
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.SDBMHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_SDBMHash64(t *testing.T) {
var x uint64 = 9881052176572890693
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.SDBMHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_RSHash(t *testing.T) {
var x uint32 = 1944033799
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.RSHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_RSHash64(t *testing.T) {
var x uint64 = 13439708950444349959
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.RSHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_JSHash(t *testing.T) {
var x uint32 = 498688898
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.JSHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_JSHash64(t *testing.T) {
var x uint64 = 13410163655098759877
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.JSHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_PJWHash(t *testing.T) {
var x uint32 = 7244206
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.PJWHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_PJWHash64(t *testing.T) {
var x uint64 = 31150
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.PJWHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_ELFHash(t *testing.T) {
var x uint32 = 7244206
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.ELFHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_ELFHash64(t *testing.T) {
var x uint64 = 31150
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.ELFHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_DJBHash(t *testing.T) {
var x uint32 = 959862602
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.DJBHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_DJBHash64(t *testing.T) {
var x uint64 = 2519720351310960458
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.DJBHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_APHash(t *testing.T) {
var x uint32 = 3998202516
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.APHash(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}
func Test_APHash64(t *testing.T) {
var x uint64 = 2531023058543352243
2020-03-19 22:56:12 +08:00
gtest.C(t, func(t *gtest.T) {
2019-06-19 09:06:52 +08:00
j := ghash.APHash64(strBasic)
2020-03-19 22:56:12 +08:00
t.Assert(j, x)
2019-06-19 09:06:52 +08:00
})
}