ADD LAStack Test test.sh

This commit is contained in:
eson 2019-04-11 01:07:09 +08:00
parent 02cf7b9672
commit 4f49401561
2 changed files with 54 additions and 21 deletions

View File

@ -3,41 +3,74 @@ package lastack
import (
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/emirpasic/gods/stacks/arraystack"
"github.com/Pallinder/go-randomdata"
)
func TestPush(t *testing.T) {
var result string
s := New()
for i := 0; i < 10; i++ {
v := randomdata.Number(0, 10)
result = spew.Sprint(s.Values())
if result != "[]" {
t.Error(result)
}
l := []int{10, 7, 3, 4, 5, 15}
for _, v := range l {
s.Push(v)
}
result = spew.Sprint(s.Values())
if result != "[15 5 4 3 7 10]" {
t.Error(result)
}
if v, ok := s.Peek(); ok {
if v != 15 {
t.Error(v)
t.Error(s.String(), " size ", s.size)
}
}
t.Error(s.Values())
for i := 0; i < 10; i++ {
v, ok := s.Pop()
t.Error(v, ok)
t.Error(s.String(), " size ", s.size)
result = spew.Sprint(s.Values())
if result != "[15 5 4 3 7 10]" {
t.Error(result)
}
var l []int
for i := 0; i < 10; i++ {
v := randomdata.Number(0, 10)
s.Push(v)
l = append(l, v)
if v, ok := s.Pop(); ok {
if v != 15 {
t.Error(v)
}
}
for i := -1; i < 11; i++ {
v, ok := s.Get(i)
t.Error(v, ok)
result = spew.Sprint(s.Values())
if result != "[5 4 3 7 10]" {
t.Error(result)
}
t.Error(l)
for s.Size() != 1 {
s.Pop()
}
result = spew.Sprint(s.Values())
if result != "[10]" {
t.Error(result)
}
if v, ok := s.Pop(); ok {
if v != 10 {
t.Error(v)
}
}
result = spew.Sprint(s.Values())
if result != "[]" {
t.Error(result)
}
}
func BenchmarkGet(b *testing.B) {

View File

@ -1 +1 @@
cd avl ; go test -v
for d in ./*/ ; do (cd "$d" && go test -v); done