hash_test.mx raw
1 package iskra
2
3 import "testing"
4
5 func TestHashDeterministic(t *testing.T) {
6 data := []byte("func main()")
7 h1 := HashBytes(data)
8 h2 := HashBytes(data)
9 if h1 != h2 {
10 t.Fatal("hash should be deterministic")
11 }
12 }
13
14 func TestHashDistinct(t *testing.T) {
15 h1 := HashBytes([]byte("func main()"))
16 h2 := HashBytes([]byte("func init()"))
17 if h1 == h2 {
18 t.Fatal("different inputs should produce different hashes")
19 }
20 }
21
22 func TestHash56Bit(t *testing.T) {
23 h := HashBytes([]byte("anything"))
24 if h>>56 != 0 {
25 t.Fatal("hash should be 56 bits (top 8 bits zero)")
26 }
27 }
28
29 func TestSegmentKeyStage(t *testing.T) {
30 key := SegmentKey(StageSRC, []byte("test"))
31 if KeyStage(key) != StageSRC {
32 t.Fatal("stage tag not preserved")
33 }
34 key2 := SegmentKey(StageBIN, []byte("test"))
35 if KeyStage(key2) != StageBIN {
36 t.Fatal("stage tag not preserved for BIN")
37 }
38 if KeyHash(key) != KeyHash(key2) {
39 t.Fatal("same content should have same hash regardless of stage")
40 }
41 if key == key2 {
42 t.Fatal("different stages should produce different keys")
43 }
44 }
45