mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
26 lines
457 B
Go
26 lines
457 B
Go
|
package collection
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestRingLess(t *testing.T) {
|
||
|
ring := NewRing(5)
|
||
|
for i := 0; i < 3; i++ {
|
||
|
ring.Add(i)
|
||
|
}
|
||
|
elements := ring.Take()
|
||
|
assert.ElementsMatch(t, []interface{}{0, 1, 2}, elements)
|
||
|
}
|
||
|
|
||
|
func TestRingMore(t *testing.T) {
|
||
|
ring := NewRing(5)
|
||
|
for i := 0; i < 11; i++ {
|
||
|
ring.Add(i)
|
||
|
}
|
||
|
elements := ring.Take()
|
||
|
assert.ElementsMatch(t, []interface{}{6, 7, 8, 9, 10}, elements)
|
||
|
}
|