Skip to content
Katabench
Try free

Test Stable Priority Ordering

Medium About 25 min Free, no account needed

Write operation sequences that distinguish priority order, FIFO ties, peeking, and queue-instance isolation.

The brief

StableQueue stores string values with signed integer priorities. Smaller numbers leave first. Equal-priority items leave in insertion order, including duplicate values.

  • Enqueue(string value, int priority) adds one item.
  • Peek() returns the next value without removing it.
  • Dequeue() returns and removes exactly the next item.
  • Count is the number of retained items.
  • Peek and dequeue on an empty queue throw InvalidOperationException.

Different queue instances never share contents. Priorities cover the full 32-bit range. Values are non-null. The contract concerns behavior, not a particular heap or list implementation.

Write a Tests class. Every public, parameterless method is a test; a test passes if it does not throw. Use Assert.Equal, True, False, and Throws<TException> as needed. Your suite must pass on the correct subject and catch every hidden mutant. Construct fresh state in each test.

Starter code

C#
public class Tests
{
    public void One_item()
    {
        var queue = new StableQueue();
        queue.Enqueue("job", 1);
        Assert.Equal("job", queue.Dequeue());
    }
}

How it is graded

You write the tests. A suite passes only when it stays green on correct code and turns enough faulty implementations red.

C# unit testing exercises →

Related guides

What it practices

Stateful testing
Drive call sequences and state-machine transitions, not just single calls.
Boundary value testing
Pin behavior exactly at, just below and just above every boundary.

Related katas