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
Test the exact number where a rule changes
The planner gives you a break once you finish at least three tasks, including the third. Code can run without errors and still get that rule wrong. A boundary is the point where the result changes. Here the boundary is three, so two, three, and four are useful numbers to check.
A test chooses an input, states the expected answer from the rule, and compares that answer with what the program actually returns. For the input three, we expect true because the rule includes the third task.
Read the code and make your prediction first. Choose Try it, then Run, to check what the example prints.
using System; bool expected = true; bool actual = EarnsBreak(3); Console.WriteLine(actual == expected); static bool EarnsBreak(int completed) => completed >= 3;
The print line compares the actual result with the expected result. It reports whether the check passed.
Change the call to EarnsBreak(2) and change expected to false. What does Console.WriteLine(actual == expected) print?
Show answer
Correct answer: B
EarnsBreak returns false below the boundary. The test expects false, so the comparison is true and the check passes.
Microsoft Learn: what makes a test readable
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 ──> ? 25 minutes ──> equal ──> ? 26 minutes ──> above ──> ?
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. Predict which check catches the change, run it, and then restore >=.
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
Compare each result with the lower and upper bounds. If a check disagrees with your prediction, trace both comparisons separately.
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. Predict CanStartSession(-1) and name the comparison that determines the result. Then decide whether the input screen should explain the rule for negative durations.
Reference: Microsoft — testing in .NET.
Sources
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.
Practice
TechInterviewNotes Editorial Team · Updated 24 Nov 2026 ·