github.phpd.cn/thought-machine/please@v12.2.0+incompatible/src/cache/tools/hash_test.go (about) 1 package tools 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestHashPoint(t *testing.T) { 11 assert.EqualValues(t, 0, HashPoint(0, 1)) 12 assert.EqualValues(t, 0, HashPoint(0, 5)) 13 assert.EqualValues(t, math.MaxUint32, HashPoint(1, 1)) 14 assert.EqualValues(t, math.MaxUint32, HashPoint(5, 5)) 15 assert.EqualValues(t, math.MaxUint32/2, HashPoint(1, 2)) 16 } 17 18 func TestHash(t *testing.T) { 19 assert.EqualValues(t, 0, Hash([]byte{0, 0, 0, 0})) 20 // Little endian... 21 assert.EqualValues(t, 1, Hash([]byte{1, 0, 0, 0})) 22 // Bytes after the fourth are ignored 23 assert.EqualValues(t, 1, Hash([]byte{1, 0, 0, 0, 15})) 24 assert.EqualValues(t, math.MaxUint32, Hash([]byte{255, 255, 255, 255})) 25 } 26 27 func TestAlternateHash(t *testing.T) { 28 // The alternate hash should move it halfway through the hash space. 29 assert.EqualValues(t, 1<<31, AlternateHash([]byte{0, 0, 0, 0})) 30 assert.EqualValues(t, 1+1<<31, AlternateHash([]byte{1, 0, 0, 0})) 31 assert.EqualValues(t, 1<<31-1, AlternateHash([]byte{255, 255, 255, 255})) 32 }