Skip to content

Commit 217d7e3

Browse files
committed
Fix test naming conventions and add unaligned data test
- Rename test functions to follow Go conventions for unexported functions - Add TestHash128_UnalignedInput to verify handling of unaligned data - Address feedback from gemini-code-assist and Copilot Signed-off-by: manmathbh <[email protected]>
1 parent 0710072 commit 217d7e3

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pkg/utils/hash/hash_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func TestHash128_AllTailLengths(t *testing.T) {
146146
}
147147
}
148148

149-
func TestRotl64(t *testing.T) {
149+
func Test_rotl64(t *testing.T) {
150150
tests := []struct {
151151
name string
152152
x uint64
@@ -202,7 +202,7 @@ func TestRotl64(t *testing.T) {
202202
}
203203
}
204204

205-
func TestFmix64(t *testing.T) {
205+
func Test_fmix64(t *testing.T) {
206206
tests := []struct {
207207
name string
208208
input uint64
@@ -241,7 +241,7 @@ func TestFmix64(t *testing.T) {
241241
}
242242
}
243243

244-
func TestFmix64_Avalanche(t *testing.T) {
244+
func Test_fmix64_Avalanche(t *testing.T) {
245245
// Test that changing a single bit in input changes many bits in output
246246
input1 := uint64(0x0123456789abcdef)
247247
input2 := uint64(0x0123456789abcdee) // flip last bit
@@ -298,4 +298,21 @@ func BenchmarkHash128_Large(b *testing.B) {
298298
for i := 0; i < b.N; i++ {
299299
Hash128(data, seed)
300300
}
301+
}
302+
303+
func TestHash128_UnalignedInput(t *testing.T) {
304+
// Create a buffer and then a sub-slice that is not 8-byte aligned.
305+
buf := make([]byte, 33)
306+
for i := range buf {
307+
buf[i] = byte(i)
308+
}
309+
unalignedData := buf[1:] // len=32
310+
311+
defer func() {
312+
if r := recover(); r != nil {
313+
t.Errorf("Hash128 panicked on unaligned data: %v", r)
314+
}
315+
}()
316+
317+
Hash128(unalignedData, 0)
301318
}

0 commit comments

Comments
 (0)