github.com/xgzlucario/GigaCache@v0.0.0-20240508025442-54204e9c8a6b/index_test.go (about) 1 package cache 2 3 import ( 4 "math" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestIndex(t *testing.T) { 12 assert := assert.New(t) 13 14 // index 15 for i := 0; i < 10000; i++ { 16 start, ttl := int(FastRand()), time.Now().UnixNano() 17 idx := newIdx(start, ttl) 18 idxx := newIdxx(start, idx) 19 assert.Equal(idx, idxx) 20 assert.Equal(idx.start(), start) 21 assert.Equal(idx.TTL()/timeCarry, ttl/timeCarry) 22 } 23 24 // panic-start 25 assert.Panics(func() { 26 newIdx(math.MaxUint32+1, 0) 27 }) 28 assert.Panics(func() { 29 newIdxx(math.MaxUint32+1, Idx{}) 30 }) 31 32 // panic-ttl 33 assert.Panics(func() { 34 newIdx(100, -1) 35 }) 36 assert.Panics(func() { 37 newIdx(100, (math.MaxUint32+1)*timeCarry) 38 }) 39 }