algorithms/fundamentals/queue/queue_test.go

36 lines
524 B
Go
Raw Permalink Normal View History

2021-11-08 21:53:15 +02:00
package queue
import (
"log"
"testing"
)
func TestSimple(t *testing.T) {
2021-12-15 23:35:58 +02:00
queue := NewQueue[int]()
2021-11-08 21:53:15 +02:00
queue.Enqueue(10)
queue.Enqueue(20)
queue.Enqueue(30)
2021-12-15 23:35:58 +02:00
first, second := queue.Dequeue(), queue.Dequeue()
2021-11-08 21:53:15 +02:00
if first != 10 && second != 20 {
log.Fatal("wrong order")
}
}
func TestSize(t *testing.T) {
2021-12-15 23:35:58 +02:00
queue := NewQueue[int]()
2021-11-08 21:53:15 +02:00
if queue.Size() != 0 {
log.Fatal("empty queue should have size 0")
}
queue.Enqueue(10)
queue.Enqueue(20)
queue.Enqueue(30)
if queue.Size() != 3 {
log.Fatal("wrong size")
}
}