bitbucket.org/ai69/amoy@v0.2.3/hash_test.go (about) 1 package amoy 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestFNV32a(t *testing.T) { 9 tests := []struct { 10 name string 11 text string 12 want uint32 13 }{ 14 {"Empty", EmptyStr, 0x811c9dc5}, 15 {"A", "A", 0xc40bf6cc}, 16 {"a", "a", 0xe40c292c}, 17 {"b", "b", 0xe70c2de5}, 18 {"Aloha", "Aloha", 0xa2d84aca}, 19 {"Long", "人活着得有个好心态,这样才能咂摸出日子的那个甜味儿来。", 0x16951d1e}, 20 } 21 for _, tt := range tests { 22 t.Run(tt.name, func(t *testing.T) { 23 if got := FNV32a(tt.text); got != tt.want { 24 t.Errorf("FNV32a(%v) = %v, want %v", tt.text, got, tt.want) 25 } 26 }) 27 } 28 } 29 30 func TestFNV64a(t *testing.T) { 31 tests := []struct { 32 name string 33 text string 34 want uint64 35 }{ 36 {"Empty", EmptyStr, 0xcbf29ce484222325}, 37 {"A", "A", 0xaf63fc4c860222ec}, 38 {"a", "a", 0xaf63dc4c8601ec8c}, 39 {"b", "b", 0xaf63df4c8601f1a5}, 40 {"Aloha", "Aloha", 0x48ace7cbbea0d4aa}, 41 {"Long", "人活着得有个好心态,这样才能咂摸出日子的那个甜味儿来。", 0x06d36942d24bac9e}, 42 } 43 for _, tt := range tests { 44 t.Run(tt.name, func(t *testing.T) { 45 if got := FNV64a(tt.text); got != tt.want { 46 t.Errorf("FNV64a(%v) = %v, want %v", tt.text, got, tt.want) 47 } 48 }) 49 } 50 } 51 52 func TestFNV128a(t *testing.T) { 53 tests := []struct { 54 name string 55 text string 56 want []byte 57 }{ 58 {"Empty", EmptyStr, []byte{0x6c, 0x62, 0x27, 0x2e, 0x07, 0xbb, 0x01, 0x42, 0x62, 0xb8, 0x21, 0x75, 0x62, 0x95, 0xc5, 0x8d}}, 59 {"A", "A", []byte{0xd2, 0x28, 0xcb, 0x69, 0x4f, 0x1a, 0x8c, 0xaf, 0x78, 0x91, 0x2b, 0x70, 0x4e, 0x4a, 0x62, 0x04}}, 60 } 61 for _, tt := range tests { 62 t.Run(tt.name, func(t *testing.T) { 63 if got := FNV128a(tt.text); !reflect.DeepEqual(got, tt.want) { 64 t.Errorf("FNV128a(%v) = %v, want %v", tt.text, got, tt.want) 65 } 66 }) 67 } 68 }