algorithms/fundamentals/stack/stack_test.go

35 lines
414 B
Go
Raw Permalink Normal View History

2021-11-08 20:32:55 +02:00
package stack
import (
"log"
"testing"
)
func TestSimple(t *testing.T) {
2021-12-15 23:43:29 +02:00
stack := NewStack[int]()
2021-11-08 20:32:55 +02:00
stack.Push(1)
stack.Push(2)
2021-12-15 23:43:29 +02:00
if stack.Pop() != 2 {
2021-11-08 20:32:55 +02:00
log.Fatal("wrong stack value")
}
}
func TestSize(t *testing.T) {
2021-12-15 23:43:29 +02:00
stack := NewStack[int]()
2021-11-08 20:32:55 +02:00
if !stack.IsEmpty() {
log.Fatal("should be empty")
}
stack.Push(1)
stack.Push(2)
stack.Push(3)
if stack.Size() != 3 {
log.Fatal("wrong size")
}
}