github.com/getlantern/mtime@v0.0.0-20200417132445-23682092d1f7/mtime_test.go (about) 1 package mtime 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 "time" 7 ) 8 9 func TestInstant(t *testing.T) { 10 delta := 1 * time.Millisecond 11 i1 := Now() 12 i2 := i1.Add(delta) 13 assert.True(t, i2 > i1) 14 assert.Equal(t, i1, i2.Add(-1*delta)) 15 assert.Equal(t, delta, i2.Sub(i1)) 16 } 17 18 func TestStopwatch(t *testing.T) { 19 elapsed := Stopwatch() 20 time.Sleep(100 * time.Millisecond) 21 e1 := elapsed() 22 time.Sleep(100 * time.Millisecond) 23 e2 := elapsed() 24 assert.True(t, e2 > e1) 25 assert.True(t, e1 > 50*time.Millisecond) 26 assert.True(t, e2 > 100*time.Millisecond) 27 }