FORTH-ish interpreter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
821 B

package main
import "testing"
func TestStackPop(t *testing.T) {
s := Stack{
values: []int{1, 2, 3},
}
i, err := s.Pop()
if err != nil {
t.Log(err.Error())
t.Fail()
}
if i != 1 {
t.Fail()
}
if len(s.values) != 2 {
t.Fail()
}
s = Stack{
values: []int{},
}
i, err = s.Pop()
if err == nil {
t.Log("expected error")
t.Fail()
}
if i != 0 {
t.Fail()
}
}
func TestStackPush(t *testing.T) {
s := Stack{
values: []int{1, 2, 3},
}
s.Push(4)
if len(s.values) != 4 {
t.Fail()
}
if s.values[0] != 4 || s.values[1] != 1 {
t.Fail()
}
}
func TestStackPick(t *testing.T) {
s := Stack{}
i, err := s.Pick(0)
if err == nil {
t.Fail()
}
if i != 0 {
t.Fail()
}
s = Stack{
values: []int{1, 2, 3},
}
i, err = s.Pick(2)
if err != nil {
t.Fail()
}
if i != 3 {
t.Fail()
}
}