Files
zyedidia.micro/cmd/micro/stack_test.go
2016-04-18 10:59:41 +00:00

40 lines
585 B
Go

package main
import "testing"
func TestStack(t *testing.T) {
stack := new(Stack)
if stack.Len() != 0 {
t.Errorf("Len failed")
}
stack.Push(5)
stack.Push("test")
stack.Push(10)
if stack.Len() != 3 {
t.Errorf("Len failed")
}
var popped interface{}
popped = stack.Pop()
if popped != 10 {
t.Errorf("Pop failed")
}
popped = stack.Pop()
if popped != "test" {
t.Errorf("Pop failed")
}
stack.Push("test")
popped = stack.Pop()
if popped != "test" {
t.Errorf("Pop failed")
}
stack.Pop()
popped = stack.Pop()
if popped != nil {
t.Errorf("Pop failed")
}
}