The same model can be used by a normal program and a test program. Main supplies input and prints a user report. PlannerTest supplies deliberate operations and checks their results directly. It does not need to feed a Scanner to test every object invariant. Both programs call the same Planner.java and Session.java.
A different entry, not a different implementation
This editor includes PlannerTest.java and selects it as the entry. Run starts its main method. The model classes stay unchanged. Open the test tab and read its labels before running; each label names a promised property rather than a private field or a particular loop implementation.
The checks cover an empty plan, valid totals, initial completion, repeated completion, invalid indexes, independent instances, topic trimming and rejected additions. A full-plan case checks the 100-session boundary and the largest allowed total. The tests do not claim to prove every possible extension. They make specific assumptions about the current API and brief.
Test the tests with a deliberate defect
After observing a passing run, introduce one defect at a time and check that the existing tests fail. Then restore the original source. A failed mutation check is useful only if the source really changed and the failure is a relevant assertion, not an unrelated syntax error. The course's automated project checks repeat this exercise for trimming, range validation, completion counting and index handling.
PlannerTest uses helper methods marked private static. They are ordinary methods, with access restricted to the test class. expectInvalid catches the expected exception, then verifies that it actually happened. If no exception is thrown, the boolean remains false and check fails.
Check your prediction
All planner checks passedThe success line appears after all checks. Open Planner.java and temporarily replace completedMinutes's isDone condition with true. The initial-completion or repeated-count evidence must fail. Reset the example before your next experiment.
public class Main {
public static void main(String[] args) {
int count = 2;
int index = 2;
boolean valid = index >= 0 && index < count;
System.out.println(valid);
System.out.println(count);
}
}Check your prediction
false
2An index equal to the size is outside the list. Returning false is useful only if the rejected operation does not also change the collection or completion flags.
Your turn
Write a boundary check helper
Write checkIndex(int index, int size) returning true only for existing zero-based positions. Use check to verify negative index, first index, last index, index==size and an empty collection. Print Index checks passed after all comparisons.
public class Main {
public static void main(String[] args) {
// Add checks for five boundary cases.
}
// Define checkIndex and check.
}Hint 1: the idea
The largest valid position is size-1, and no position is valid when size is zero.
Hint 2: a first step
Use a strict upper comparison. Pick checks on both sides of the boundary instead of several ordinary middle positions.
Show one solution
public class Main {
public static void main(String[] args) {
check("negative", !checkIndex(-1, 2));
check("first", checkIndex(0, 2));
check("last", checkIndex(1, 2));
check("at size", !checkIndex(2, 2));
check("empty", !checkIndex(0, 0));
System.out.println("Index checks passed");
}
static boolean checkIndex(int index, int size) {
return index >= 0 && index < size;
}
static void check(String label, boolean condition) {
if (!condition) {
throw new AssertionError(label);
}
}
}Index checks passedindex < size is the deciding comparison: with <=, the "at size" check fails,
which is exactly the out-of-bounds bug Planner.complete guards against. The
"empty" check shows that with size 0 no index is valid, not even 0.
Change it and explain
Temporarily change topic.trim() to topic in Session's stored-field assignment; which check catches it? Restore it. Then remove the duration range guard and confirm that invalid additions are rejected by the tests. Do not judge a mutation by whether the original demo still prints its old output.
Add one test of your own before extending the project: complete the second session and expect all 35 minutes completed. Run it on the correct implementation, then explain which plausible mistake it can distinguish. Keep test cases close to the contract, so a harmless refactor does not require rewriting every test.
Completion is saved in this browser only. It does not measure mastery.