ring_test.go 537 B

12345678910111213141516171819202122232425262728293031
  1. package collection
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestNewRing(t *testing.T) {
  7. assert.Panics(t, func() {
  8. NewRing(0)
  9. })
  10. }
  11. func TestRingLess(t *testing.T) {
  12. ring := NewRing(5)
  13. for i := 0; i < 3; i++ {
  14. ring.Add(i)
  15. }
  16. elements := ring.Take()
  17. assert.ElementsMatch(t, []interface{}{0, 1, 2}, elements)
  18. }
  19. func TestRingMore(t *testing.T) {
  20. ring := NewRing(5)
  21. for i := 0; i < 11; i++ {
  22. ring.Add(i)
  23. }
  24. elements := ring.Take()
  25. assert.ElementsMatch(t, []interface{}{6, 7, 8, 9, 10}, elements)
  26. }