123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package door
- // Need net, flag for setupSockets
- import (
- "testing"
- )
- func TestFIFOEmptyRune(t *testing.T) {
- buffer := NewFIFOBuffer[rune](3)
- defer func() {
- if r := recover(); r == nil {
- t.Error("Pop of empty FIFO Buffer did not panic.")
- }
- }()
- buffer.Push(rune(1))
- x := buffer.Pop()
- if x != rune(1) {
- t.Errorf("Buffer did not return expected value 1: %d", x)
- }
- _ = buffer.Pop()
- }
- func TestFIFOOverflowRune(t *testing.T) {
- buffer := NewFIFOBuffer[rune](3)
- defer func() {
- if r := recover(); r == nil {
- t.Error("Pop of empty FIFO Buffer did not panic.")
- }
- }()
- buffer.Push(rune(1))
- buffer.Push(rune(2))
- buffer.Push(rune(3))
- buffer.Push(rune(4))
- t.Errorf("buffer.Push should have paniced.")
- }
- func TestFIFOEmptyInt(t *testing.T) {
- buffer := NewFIFOBuffer[int](3)
- defer func() {
- if r := recover(); r == nil {
- t.Error("Pop of empty FIFO Buffer did not panic.")
- }
- }()
- buffer.Push(1)
- x := buffer.Pop()
- if x != 1 {
- t.Errorf("Buffer did not return expected value 1: %d", x)
- }
- _ = buffer.Pop()
- }
- func TestFIFOOverflowInt(t *testing.T) {
- buffer := NewFIFOBuffer[int](3)
- defer func() {
- if r := recover(); r == nil {
- t.Error("Pop of empty FIFO Buffer did not panic.")
- }
- }()
- buffer.Push(1)
- buffer.Push(2)
- buffer.Push(3)
- buffer.Push(4)
- t.Errorf("buffer.Push should have paniced.")
- }
- func TestFIFOInt(t *testing.T) {
- buffer := NewFIFOBuffer[int](3)
- buffer.Push(10)
- buffer.Push(20)
- x := buffer.Pop()
- if x != 20 {
- t.Errorf("Buffer did not return expected value 20: %d", x)
- }
- x = buffer.Pop()
- if x != 10 {
- t.Errorf("Buffer did not return expected value 10: %d", x)
- }
- if !buffer.Empty() {
- t.Errorf("Buffer is not empty.")
- }
- buffer.Push(30)
- x = buffer.Pop()
- if x != 30 {
- t.Errorf("Buffer did not return expected value 30: %d", x)
- }
- }
- func TestFIFOStr(t *testing.T) {
- buffer := NewFIFOBuffer[string](2)
- buffer.Push("Fish")
- buffer.Push("Cat")
- x := buffer.Pop()
- if x != "Cat" {
- t.Errorf("Expected Cat, got %s", x)
- }
- x = buffer.Pop()
- if x != "Fish" {
- t.Errorf("Expected Fish, got %s", x)
- }
- }
|