44 lines
890 B
Go
44 lines
890 B
Go
package scopes_test
|
|
|
|
import (
|
|
tbase "testing"
|
|
|
|
"git.sr.ht/~cco/go-scopes/common/stack"
|
|
"git.sr.ht/~cco/go-scopes/common/voc"
|
|
"git.sr.ht/~cco/go-scopes/testing"
|
|
)
|
|
|
|
func TestCommon(tb *tbase.T) {
|
|
t := testing.SetUp(tb)
|
|
t.Run("stack", StackTest)
|
|
t.Run("voc", VocTest)
|
|
}
|
|
|
|
func StackTest(t *testing.T) {
|
|
var st stack.Stack[int] = stack.NewStack[int]()
|
|
st.Push(3)
|
|
st.Push(4)
|
|
t.AssertEqual(st.Depth(), 2)
|
|
st.Push(5)
|
|
t.AssertEqual(st.Peek(0), 5)
|
|
st.Replace(1, 99)
|
|
st.Push(6)
|
|
t.AssertEqual(st.Peek(2), 99)
|
|
st.Push(7)
|
|
st.Push(8)
|
|
st.Push(9)
|
|
t.AssertEqual(st.Peek(2), 7)
|
|
st.Pop()
|
|
t.AssertEqual(st.Pop(), 8)
|
|
t.AssertEqual(st.Peek(st.Depth()-1), 3)
|
|
}
|
|
|
|
func VocTest(t *testing.T) {
|
|
v1 := voc.NewVoc[int](nil)
|
|
v1.Register("one", 1)
|
|
m := v1.Lookup("one")
|
|
t.AssertEqual(m.IsNothing(), false)
|
|
t.AssertEqual(m.Value(), 1)
|
|
m = v1.Lookup("two")
|
|
t.AssertEqual(m.IsNothing(), true)
|
|
}
|