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.Countis 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
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.
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
- Test Fenced Lease Ownership Hard Free Exercise expiry, renewal, ownership transfer, and stale-token rejection in a lease that must never reuse authority.
- Test the Sliding-Window Rate Limiter Hard Free You're given a correct sliding-window rate limiter. Write the call sequences that prove the window slides and the limit holds.
- Test the Stock Reservations Hard Free You're given a correct stock ledger whose holds expire. Write the sequences that prove no unit is sold twice or stranded on an expired hold.
- Test the Caesar Cipher Medium Free You're given a correct Caesar cipher. Write the tests that pin wraparound, case, non-letters, and shift normalization.