LeetCode/go/implement-queue-using-stacks_test.go

50 lines
709 B
Go
Raw Normal View History

package implement_queue_using_stacks
import (
"testing"
)
func TestEmpty(t *testing.T) {
obj := Constructor()
if !obj.Empty() {
t.Error("Queue should be empty")
}
}
func TestBasic(t *testing.T) {
q := Constructor()
q.Push(1)
q.Push(2)
if q.Peek() != 1 {
t.Error("1 should be at the front of the queue")
}
if q.Pop() != 1 {
t.Error("1 should've been removed from the queue")
}
if q.Empty() {
t.Error("Queue shouldn't be empty")
}
q.Push(3)
if q.Pop() != 2 {
t.Error("Queue should've removed 2")
}
if q.Empty() {
t.Error("Queue shouldn't be empty")
}
if q.Pop() != 3 {
t.Error("Queue should've removed 3")
}
if !q.Empty() {
t.Error("Queue should be empty")
}
}