From 0840eb9272ad4f97f17959b7891ad310a803d511 Mon Sep 17 00:00:00 2001 From: Sam Fredrickson Date: Fri, 3 Mar 2023 22:34:58 -0800 Subject: [PATCH] Add test for invalid priority levels to npq. --- npq/lib_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/npq/lib_test.go b/npq/lib_test.go index e74f0e1..026a701 100644 --- a/npq/lib_test.go +++ b/npq/lib_test.go @@ -48,6 +48,26 @@ func TestSendClosedPanic(t *testing.T) { q.Send(1, 1) } +func TestTooLowPriorityPanic(t *testing.T) { + testInvalidPriorityPanic(t, 0) +} + +func TestTooHighPriorityPanic(t *testing.T) { + testInvalidPriorityPanic(t, 3) +} + +func testInvalidPriorityPanic(t *testing.T, invalid int) { + t.Parallel() + defer func() { + if r := recover(); r == nil { + t.Errorf("sending with invalid priority did not panic") + } + }() + q := npq.Make[int, int](4, 1, 2) + q.Send(invalid, 1) + +} + func TestRecvClosed(t *testing.T) { t.Parallel() q := npq.Make[int, int](4, 1, 2)