ring_test.go 457 B

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