aqi/ws/context_lang_i18n_hash_test.go
2024-06-18 18:09:39 +08:00

42 lines
684 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ws
import (
"fmt"
"hash/fnv"
"log"
"testing"
)
func TestHash(t *testing.T) {
msgList := []string{
"1",
"2",
"a",
"aa",
"123",
"12",
"hello",
"hella",
"用户注册失败",
"用户注册失败1",
"用户注册没失败",
"注册失败",
"失败",
"用户失败",
}
for _, msg := range msgList {
h := fnv.New32a()
_, err := h.Write([]byte(msg))
if err != nil {
return
}
mHash := fmt.Sprintf("%03d", h.Sum32()%1000)
mHash1 := fmt.Sprintf("%04d", h.Sum32()%10000)
mHash2 := fmt.Sprintf("%03x", h.Sum32()%4096)
log.Printf("%s -> (%s, %s, %d) -> %s%d) \n", msg, mHash, mHash1, h.Sum32(), mHash2, h.Sum32()%4096)
}
}