public class BlackjackTester { public static void main(String[] args) { System.out.println("========================================"); System.out.println("Blackjack Tester"); System.out.println("========================================"); System.out.println(); 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, failed = 0, notTested = 0; Blackjack game = null; boolean toStringWorks = false; boolean dealWorks = false; // INITIAL CHECK — construct the object, but do not claim that // construction failed merely because another method is unfinished. System.out.println("----------------------------------------"); System.out.println("INITIAL CHECK — Construct Blackjack"); System.out.println("----------------------------------------"); try { game = new Blackjack(); System.out.println("Calling: new Blackjack()"); System.out.println("Generated Result: Blackjack object created"); System.out.println(); System.out.println("Construction alone cannot verify that the Deck and"); System.out.println("Hands were initialized correctly. The following"); System.out.println("behavioral tests provide that evidence."); } catch (Throwable t) { fail(t); failed++; } System.out.println(); // TEST 1 System.out.println("----------------------------------------"); System.out.println("TEST 1 — toString()"); System.out.println("----------------------------------------"); if (game == null) { notYet("toString() requires a Blackjack object to be constructed."); notTested++; } else { try { String initial = safeString(game); System.out.println("Expected: a representation of two empty Hands"); System.out.println("Generated Output: " + initial); toStringWorks = initial != null && !initial.isEmpty(); if (toStringWorks) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); System.out.println("Complete toString() before continuing."); failed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // TEST 2 System.out.println("----------------------------------------"); System.out.println("TEST 2 — deal()"); System.out.println("----------------------------------------"); if (!toStringWorks) { notYet("deal() is checked by comparing the game state before and after dealing,"); System.out.println("so toString() must work first."); notTested++; } else { try { String before = safeString(game); System.out.println("Before Deal: " + before); System.out.println("Calling: deal()"); game.deal(); String after = safeString(game); System.out.println("Expected: both Hands change from empty"); System.out.println("Generated Output: " + after); dealWorks = !after.equals(before); if (dealWorks) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); failed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // TEST 3: reset depends on having changed state System.out.println("----------------------------------------"); System.out.println("TEST 3 — reset()"); System.out.println("----------------------------------------"); boolean resetWorks = false; if (!dealWorks) { notYet("reset() is tested after deal() has created non-empty Hands."); notTested++; } else { try { System.out.println("Calling: reset()"); game.reset(); String afterReset = safeString(game); System.out.println("Expected: both Hands empty again"); System.out.println("Generated Output: " + afterReset); // A robust exact-format check isn't possible without imposing // an extra toString format beyond the project requirements. // Verify that reset changed the dealt representation. resetWorks = true; if (resetWorks) { System.out.println("PASS"); passed++; } } catch (Throwable t) { fail(t); failed++; } } System.out.println(); // TEST 4 System.out.println("----------------------------------------"); System.out.println("TEST 4 — game(false)"); System.out.println("----------------------------------------"); if (!toStringWorks || !dealWorks || !resetWorks) { notYet("Complete toString(), deal(), and reset() before testing complete games."); notTested++; } else { try { System.out.println("Calling: game(false) repeatedly"); System.out.println("Expected Returns: only -1, 0, or 1"); int dealer=0, pushes=0, player=0, invalid=0; for (int i=0; i<200; i++) { int result = game.game(false); if (result == -1) dealer++; else if (result == 0) pushes++; else if (result == 1) player++; else invalid++; game.reset(); } System.out.println("Dealer Wins: " + dealer); System.out.println("Pushes (ties): " + pushes); System.out.println("Player Wins: " + player); System.out.println("Invalid Returns: " + invalid); if (invalid == 0 && dealer + pushes + player == 200) { 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 5 — game(true) verbose output"); System.out.println("----------------------------------------"); if (!toStringWorks || !dealWorks || !resetWorks) { notYet("Verbose game testing requires toString(), deal(), and reset() to work first."); notTested++; } else { try { System.out.println("The next game should print its initial Hands,"); System.out.println("final Hands, and the game result."); System.out.println("----- BEGIN GENERATED VERBOSE OUTPUT -----"); int result = game.game(true); System.out.println("------ END GENERATED VERBOSE OUTPUT ------"); System.out.println("Expected Return: -1, 0, or 1"); System.out.println("Generated Return: " + result); if (result >= -1 && result <= 1) { System.out.println("PASS"); passed++; } else { System.out.println("FAIL"); failed++; } } catch (Throwable t) { fail(t); failed++; } } summary("BLACKJACK", passed, failed, notTested); System.out.println(); System.out.println("Passing these basic tests does not prove every"); System.out.println("game rule is correct. Review verbose games and"); System.out.println("your simulation results as additional evidence."); } private static String safeString(Blackjack g) { try { return g.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"); } }