|
@@ -5,7 +5,7 @@ import (
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
-func TestFIFOEmpty(t *testing.T) {
|
|
|
+func TestFIFOEmptyRune(t *testing.T) {
|
|
|
buffer := NewFIFOBuffer[rune](3)
|
|
|
|
|
|
defer func() {
|
|
@@ -23,7 +23,7 @@ func TestFIFOEmpty(t *testing.T) {
|
|
|
_ = buffer.Pop()
|
|
|
}
|
|
|
|
|
|
-func TestFIFOOverflow(t *testing.T) {
|
|
|
+func TestFIFOOverflowRune(t *testing.T) {
|
|
|
buffer := NewFIFOBuffer[rune](3)
|
|
|
|
|
|
defer func() {
|
|
@@ -36,5 +36,61 @@ func TestFIFOOverflow(t *testing.T) {
|
|
|
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)
|
|
|
+ }
|
|
|
}
|