Skip to content
Katabench
Try free

Test Signed Time Buckets

Easy About 15 min Free, no account needed

Write boundary tests for floor-based time buckets, where negative timestamps expose truncation bugs.

The brief

TimeBuckets.Start(long timestamp, int width) returns the start of the width-sized bucket containing timestamp. Buckets are [k * width, (k + 1) * width) for every integer k, including negative k.

For width 10, timestamps 0..9 map to 0; -10..-1 map to -10. Nonpositive width throws ArgumentOutOfRangeException. Width may be any positive 32-bit integer. Test timestamps and results within -10^12..10^12.

This is floor division, not truncation toward zero. Test the public contract, including exact boundaries and values too large for a 32-bit intermediate.

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 Positive_boundary()
    {
        Assert.Equal(20L, new TimeBuckets().Start(20, 10));
    }
}

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.

Related katas