Skip to content
Katabench
Try free

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:

C#
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 start up to, but not including, end. A notification at exactly the start time is held back; one at exactly the end time goes out.
  • When end is earlier than start, the window wraps past midnight: 22:00 to 07:00 is quiet late in the evening and again in the early morning.
  • When start is earlier than end, the window stays within one day: 12:00 to 14:00 is quiet over lunch only.
  • When start equals end, quiet hours are switched off and nothing is held back.
  • NextDeliveryAt returns sentAt unchanged when the notification is not held back. A held notification goes out at the first moment after sentAt when the clock reads end.

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

C#
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.

C# unit testing exercises →

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