diff --git a/lastack/lastack_test.go b/lastack/lastack_test.go index 992ad81..808b997 100644 --- a/lastack/lastack_test.go +++ b/lastack/lastack_test.go @@ -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) - 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.Peek(); 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 != "[15 5 4 3 7 10]" { + t.Error(result) } - t.Error(l) + + if v, ok := s.Pop(); ok { + if v != 15 { + t.Error(v) + } + } + + result = spew.Sprint(s.Values()) + if result != "[5 4 3 7 10]" { + t.Error(result) + } + + 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) { diff --git a/test.sh b/test.sh index c3874fe..e805bdd 100644 --- a/test.sh +++ b/test.sh @@ -1 +1 @@ -cd avl ; go test -v +for d in ./*/ ; do (cd "$d" && go test -v); done