github.com/zerjioang/time32@v0.0.0-20211102104504-b756043b9843/ticker_test.go (about) 1 package time32 2 3 import ( 4 "fmt" 5 "github.com/stretchr/testify/assert" 6 "math" 7 "testing" 8 ) 9 10 func TestTicker(t *testing.T) { 11 t.Run("reuse-time", func(t *testing.T) { 12 tt := Now() 13 reusedTt := ReuseTime() 14 assert.Equal(t, tt.Unix(), reusedTt.Unix()) 15 }) 16 t.Run("reuse-unix", func(t *testing.T) { 17 tt := Now() 18 reusedTt := ReuseUnix() 19 assert.Equal(t, tt.Unix(), reusedTt) 20 }) 21 t.Run("reuse-nanos", func(t *testing.T) { 22 tt := Now() 23 reusedTt := ReuseUnixNano() 24 diff := math.Abs(float64(tt.UnixNano()-reusedTt)) 25 fmt.Println(diff) 26 assert.True(t, diff < 0.2*1000*1000) 27 }) 28 }