Module 4 · Reliable programs: copy, handle errors and check results · Lesson 16 of 20
Check behaviour: catch a boundary bug before it reaches a learner
The code builds, but exactly 25 minutes fails a 25-minute goal. What check would catch that mistake next time? Turn the boundary rule into repeatable checks.
Predict a bug
The requirement is: 25 minutes or more meets a 25-minute goal. Before running, predict this program. Then decide whether the observed result satisfies the requirement.
using System;
Console.WriteLine(IsGoalMet(25, 25));
static bool IsGoalMet(int minutes, int goal)
{
return minutes > goal;
}The program prints False. Which explanation identifies the defect?
Show answer
Correct answer: A
The requirement includes equality. The current > comparison excludes the exact boundary.
Option B: WriteLine can print a bool.
Option C: A bool expression is already a usable result.
Option D: One comparison is sufficient; a loop would not fix it.
Hint: Read “or more” in the requirement.
Choose checks from the requirement
Requirement: minutes >= goal 24 minutes ──> below ──> False 25 minutes ──> equal ──> True 26 minutes ──> above ──> True
A check needs an input, an expected result and a comparison with the actual result. “The program ran” is not the same as “the result meets the requirement.” The three neighbouring values make the boundary visible.
Run repeatable checks
The small Check method below prints a pass or throws on failure. It uses no extra packages. This is a first step toward automated tests; a formal test framework gives you richer discovery and reporting later.
using System;
Check("below the goal", IsGoalMet(24, 25) == false);
Check("exactly the goal", IsGoalMet(25, 25) == true);
Check("above the goal", IsGoalMet(26, 25) == true);
Check("zero goal", IsGoalMet(0, 0) == true);
static bool IsGoalMet(int minutes, int goal)
{
return minutes >= goal;
}
static void Check(string name, bool passed)
{
if (!passed)
{
throw new InvalidOperationException("FAIL: " + name);
}
Console.WriteLine("PASS: " + name);
}Change only >= to > inside IsGoalMet and run again. The “exactly the goal” check should fail. Restore >= afterward. A check that can catch the original mistake gives you useful evidence about this requirement.
Which set is most useful for checking this boundary?
Show answer
Correct answer: C
Below, equal and above exercise both sides and the exact transition.
Option A: Repeating one value does not cover both sides.
Option B: All three inputs are below 25 and miss the equality bug.
Option D: A large number cannot tell you whether equality is handled.
Your turn: test a different rule
Write CanStartSession(int minutes) for the rule “a session must be at least 5 minutes and at most 90 minutes.” Before coding, write the expected results for 4, 5, 90 and 91. Implement the method and add four Check calls in your own project.
Stop here and run your attempt. Each check should name the input and compare the returned bool with the rule.
Hint
Both comparisons must hold: at least 5, and at most 90.
Compare your result
The answer sequence is False, True, True, False. An implementation can return minutes >= 5 && minutes <= 90.
A check fails after you change a method. What is the best first step?
Show answer
Correct answer: B
A failure tells you a promised behaviour may have changed. First establish whether the expectation or implementation is wrong.
Option A: Deleting the evidence does not fix the behaviour.
Option C: Swallowing the failure hides a defect.
Option D: Unexplained changes make the cause harder to find.
Explain it back
Explain why a passing compile is weaker evidence than these four checks. What does CanStartSession(-1) return, and which comparison rejects it? The predicate already returns false for negative values. Separately decide whether the input screen should explain that a duration cannot be negative.
Reference: Microsoft — testing in .NET.
Quick reference
- Read the requirement before choosing test inputs.
- Check below, equal to and above a boundary.
- Compare actual and expected behaviour.
- A failing check is information to investigate.
- Keep validation policy explicit.
TechInterviewNotes Editorial Team · Updated 27 Oct 2026 ·