show last element in stack string

This commit is contained in:
sentriz
2019-07-01 13:13:26 +01:00
parent b27d7e7aab
commit e517c7538c
5 changed files with 110 additions and 108 deletions

View File

@@ -0,0 +1,40 @@
package stack
import (
"testing"
"github.com/sentriz/gonic/model"
)
func egAlbum(id int) *model.Album {
return &model.Album{IDBase: model.IDBase{id}}
}
func TestFolderStack(t *testing.T) {
sta := &Stack{}
sta.Push(egAlbum(3))
sta.Push(egAlbum(4))
sta.Push(egAlbum(5))
sta.Push(egAlbum(6))
expected := "[6, 5, 4, 3, ]"
actual := sta.String()
if expected != actual {
t.Errorf("first stack: expected string %q, got %q",
expected, actual)
}
//
sta = &Stack{}
sta.Push(egAlbum(27))
sta.Push(egAlbum(4))
sta.Peek()
sta.Push(egAlbum(5))
sta.Push(egAlbum(6))
sta.Push(egAlbum(7))
sta.Pop()
expected = "[6, 5, 4, 27, ]"
actual = sta.String()
if expected != actual {
t.Errorf("second stack: expected string %q, got %q",
expected, actual)
}
}