assert len > 0

This commit is contained in:
kevin
2020-10-15 14:25:10 +08:00
parent 901fadb5d3
commit 8291eabc2c
4 changed files with 23 additions and 0 deletions

View File

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

View File

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