public class HandTester { public static void main(String[] args) { System.out.println("========================================"); System.out.println("Hand Tester"); System.out.println("========================================"); System.out.println(); System.out.println("Work through the tests in order."); System.out.println("PASS means the behavior was tested and worked."); System.out.println("FAIL means the behavior was tested and did not work."); System.out.println("NOT TESTED YET means an earlier behavior must work first."); System.out.println(); int passed = 0; int failed = 0; int notTested = 0; Hand hand = null; // INITIAL CHECK: useful context, but not counted as a test because // an unfinished size() stub can also return 0. System.out.println("----------------------------------------"); System.out.println("INITIAL CHECK — Constructor and empty size()"); System.out.println("----------------------------------------"); try { hand = new Hand(); System.out.println("Calling: new Hand()"); System.out.println("Expected Size: 0"); System.out.println("Generated Size: " + hand.size()); System.out.println(); System.out.println("A new Hand should have size 0, but this check alone"); System.out.println("cannot verify size() because the unfinished skeleton"); System.out.println("also returns 0. TEST 1 verifies size() after add()."); } catch (Throwable t) { fail(t); failed++; } System.out.println(); boolean addWorks = false; // TEST 2: add is the gateway System.out.println("----------------------------------------"); System.out.println("TEST 1 — add() and size()"); System.out.println("----------------------------------------"); if (hand == null) { notYet("A Hand must be constructed before add() can be tested."); notTested++; } else { try { System.out.println("Starting Size: " + hand.size()); System.out.println("Calling: add(new Card(5))"); hand.add(new Card(5)); System.out.println("Expected Size: 1"); System.out.println("Generated Size: " + hand.size()); addWorks = hand.size() == 1; if (addWorks) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); System.out.println("Complete add() and size() before continuing."); failed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // Build a known hand only if add works. boolean knownHandReady = false; if (addWorks) { try { hand.add(new Card(2)); hand.add(new Card(3)); knownHandReady = hand.size() == 3; } catch (Throwable ignored) { knownHandReady = false; } } // TEST 3 System.out.println("----------------------------------------"); System.out.println("TEST 2 — getCard()"); System.out.println("----------------------------------------"); if (!knownHandReady) { notYet("getCard() requires add() and size() to work first."); notTested++; } else { try { System.out.println("Generated Hand: " + safeString(hand)); System.out.println("Calling: getCard(1)"); Card c = hand.getCard(1); System.out.println("Expected Return: 2"); System.out.println("Generated Return: " + (c == null ? "null" : c.getValue())); if (c != null && c.getValue() == 2) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); failed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // TEST 4 System.out.println("----------------------------------------"); System.out.println("TEST 3 — getTotalValue()"); System.out.println("----------------------------------------"); if (!knownHandReady) { notYet("getTotalValue() requires a Hand containing known Cards."); notTested++; } else { try { System.out.println("Expected Total: 10"); System.out.println("Generated Total: " + hand.getTotalValue()); if (hand.getTotalValue() == 10) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); failed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // TEST 5 System.out.println("----------------------------------------"); System.out.println("TEST 4 — toString()"); System.out.println("----------------------------------------"); if (!knownHandReady) { notYet("toString() requires a Hand containing known Cards."); notTested++; } else { try { System.out.println("Expected Output: [5, 2, 3] : 10"); System.out.println("Generated Output: " + safeString(hand)); if ("[5, 2, 3] : 10".equals(hand.toString())) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); failed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // TEST 6 System.out.println("----------------------------------------"); System.out.println("TEST 5 — reset()"); System.out.println("----------------------------------------"); if (!knownHandReady) { notYet("reset() requires a non-empty Hand created with working add()."); notTested++; } else { try { System.out.println("Before Reset: " + safeString(hand)); System.out.println("Calling: reset()"); hand.reset(); System.out.println("Expected Size: 0"); System.out.println("Generated Size: " + hand.size()); System.out.println("Expected Total: 0"); System.out.println("Generated Total: " + hand.getTotalValue()); boolean ok = hand.size() == 0 && hand.getTotalValue() == 0; if (ok) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); failed++; } } catch (Throwable t) { fail(t); failed++; } } summary("HAND", passed, failed, notTested); } private static String safeString(Hand h) { try { return h.toString(); } catch (Throwable t) { return ""; } } private static void notYet(String reason) { System.out.println("NOT TESTED YET"); System.out.println(reason); } private static void fail(Throwable t) { System.out.println("FAIL"); System.out.println("Generated Error: " + t.getClass().getSimpleName() + (t.getMessage() == null ? "" : " — " + t.getMessage())); } private static void summary(String name, int passed, int failed, int notTested) { System.out.println(); System.out.println("========================================"); System.out.println(name + " TESTER RESULTS"); System.out.println("========================================"); System.out.println("Passed: " + passed); System.out.println("Failed: " + failed); System.out.println("Not tested yet: " + notTested); System.out.println(failed == 0 && notTested == 0 ? name + " TESTER PASS" : name + " NOT YET COMPLETE"); } }