1
0

date_counter_test.go 514 B

123456789101112131415161718192021222324252627
  1. package metric
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestDateCounter(t *testing.T) {
  7. assert := assert.New(t)
  8. dc := NewDateCounter(3)
  9. dc.Inc(10)
  10. assert.EqualValues(10, dc.TodayCount())
  11. dc.Dec(5)
  12. assert.EqualValues(5, dc.TodayCount())
  13. counts := dc.GetLastDaysCount(3)
  14. assert.EqualValues(3, len(counts))
  15. assert.EqualValues(5, counts[0])
  16. assert.EqualValues(0, counts[1])
  17. assert.EqualValues(0, counts[2])
  18. dcTmp := dc.Snapshot()
  19. assert.EqualValues(5, dcTmp.TodayCount())
  20. }