1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/go/implement-queue-using-stacks_test.go
Matej Focko d2ef757754
go: allow testing
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-06-16 11:44:08 +02:00

49 lines
733 B
Go

package main
import (
"testing"
)
func Test_ImplementQueueUsingStacks_Empty(t *testing.T) {
obj := NewQueue()
if !obj.Empty() {
t.Error("Queue should be empty")
}
}
func Test_ImplementQueueUsingStacks_Basic(t *testing.T) {
q := NewQueue()
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")
}
}