Test the Quiet-Hours Window
Easy About 20 min Free, no account needed
You're given a correct quiet-hours check for notifications. Write the tests that pin both edges of the window and the day a held message goes out.
The brief
A notification service holds messages back during each user's quiet hours and sends them when the window ends. Most users pick an overnight window such as 22:00 to 07:00, which wraps past midnight. The code here is already written and correct. Your job is to write the tests that prove it.
Here is the code under test:
public class QuietHours
{
public QuietHours(TimeOnly start, TimeOnly end) { ... }
// True when a notification sent at `time` must be held back.
public bool IsQuiet(TimeOnly time) { ... }
// When a notification sent at `sentAt` actually goes out.
public DateTime NextDeliveryAt(DateTime sentAt) { ... }
}The rules:
- Quiet hours run from
startup to, but not including,end. A notification at exactly the start time is held back; one at exactly the end time goes out. - When
endis earlier thanstart, the window wraps past midnight: 22:00 to 07:00 is quiet late in the evening and again in the early morning. - When
startis earlier thanend, the window stays within one day: 12:00 to 14:00 is quiet over lunch only. - When
startequalsend, quiet hours are switched off and nothing is held back. NextDeliveryAtreturnssentAtunchanged when the notification is not held back. A held notification goes out at the first moment aftersentAtwhen the clock readsend.
TimeOnly is a time of day: new TimeOnly(22, 0) is 22:00. DateTime values here are plain
local date and times with no time zone, such as new DateTime(2026, 3, 1, 23, 30, 0).
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 (no using needed
for Assert). Your suite must pass on the correct QuietHours and catch every hidden mutant, a
planted-bug version you never see.
Starter code
using System;
public class Tests
{
public void An_afternoon_notification_is_not_held_back()
{
var quietHours = new QuietHours(new TimeOnly(22, 0), new TimeOnly(7, 0));
Assert.False(quietHours.IsQuiet(new TimeOnly(15, 0)));
}
}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.
What it practices
- Boundary value testing
- Pin behavior exactly at, just below and just above every boundary.
- Equivalence partitioning
- Cover each class of input and every branch with one deliberate case.
- Dates, times and ranges
- Time zones, local day boundaries, month arithmetic and half-open range overlap.
Related katas
- Test the Clamp Function Easy Free You're given a correct clamp function. Write the tests that cover below, above, inside, and the boundaries.
- 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.
- Test the Password Policy Medium Free You're given a correct password validator with four rules. Write tests that isolate each rule so a dropped one is caught.
- Test the Triangle Classifier Medium Free You're given a correct triangle classifier. Write the tests that cover every shape and the invalid cases.