assert len > 0

master
kevin 4 years ago
parent 901fadb5d3
commit 8291eabc2c

@ -6,6 +6,10 @@ type Ring struct {
} }
func NewRing(n int) *Ring { func NewRing(n int) *Ring {
if n < 1 {
panic("n should be greater than 0")
}
return &Ring{ return &Ring{
elements: make([]interface{}, n), elements: make([]interface{}, n),
} }

@ -6,6 +6,12 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestNewRing(t *testing.T) {
assert.Panics(t, func() {
NewRing(0)
})
}
func TestRingLess(t *testing.T) { func TestRingLess(t *testing.T) {
ring := NewRing(5) ring := NewRing(5)
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {

@ -162,6 +162,7 @@ func (p Stream) Head(n int64) Stream {
if n < 1 { if n < 1 {
panic("n must be greater than 0") panic("n must be greater than 0")
} }
source := make(chan interface{}) source := make(chan interface{})
go func() { go func() {
@ -247,6 +248,10 @@ func (p Stream) Sort(less LessFunc) Stream {
} }
func (p Stream) Tail(n int64) Stream { func (p Stream) Tail(n int64) Stream {
if n < 1 {
panic("n should be greater than 0")
}
source := make(chan interface{}) source := make(chan interface{})
go func() { go func() {

@ -294,6 +294,14 @@ func TestTail(t *testing.T) {
assert.Equal(t, 7, result) assert.Equal(t, 7, result)
} }
func TestTailZero(t *testing.T) {
assert.Panics(t, func() {
Just(1, 2, 3, 4).Tail(0).Reduce(func(pipe <-chan interface{}) (interface{}, error) {
return nil, nil
})
})
}
func TestWalk(t *testing.T) { func TestWalk(t *testing.T) {
var result int var result int
Just(1, 2, 3, 4, 5).Walk(func(item interface{}, pipe chan<- interface{}) { Just(1, 2, 3, 4, 5).Walk(func(item interface{}, pipe chan<- interface{}) {

Loading…
Cancel
Save