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
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.
What it practices
- Boundary value testing
- Pin behavior exactly at, just below and just above every boundary.
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 Grade Boundaries Easy Free You're given a correct score-to-letter grader. Write the boundary tests that pin every cutoff and catch an off-by-one.
- Test the Quiet-Hours Window Easy Free 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.
- 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.