Skip to content

Commit 04ed637

Browse files
authored
test(hash): add unit tests for Hash, Hash determinism, and Md5Hex edg… (#5469)
1 parent 567087a commit 04ed637

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

core/hash/hash_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@ func TestMd5Hex(t *testing.T) {
2525
assert.Equal(t, md5Digest, actual)
2626
}
2727

28+
func TestHash(t *testing.T) {
29+
result := Hash([]byte(text))
30+
assert.NotEqual(t, uint64(0), result)
31+
}
32+
33+
func TestHash_Deterministic(t *testing.T) {
34+
data := []byte("consistent-hash-test")
35+
first := Hash(data)
36+
second := Hash(data)
37+
assert.Equal(t, first, second)
38+
}
39+
40+
func TestHash_Empty(t *testing.T) {
41+
// Hash should not panic on empty input.
42+
result := Hash([]byte{})
43+
_ = result
44+
}
45+
46+
func TestMd5Hex_Empty(t *testing.T) {
47+
result := Md5Hex([]byte{})
48+
assert.Equal(t, 32, len(result))
49+
}
50+
2851
func BenchmarkHashFnv(b *testing.B) {
2952
for i := 0; i < b.N; i++ {
3053
h := fnv.New32()

0 commit comments

Comments
 (0)