From 43520541a384c8d4f31098d40b5ad6a82d355c6b Mon Sep 17 00:00:00 2001 From: Anthony Fierro Date: Tue, 16 Apr 2024 15:50:01 -0500 Subject: [PATCH] corrected test to deal with new code --- src/test/java/uta/cse3310/GameLogicTest.java | 41 +++++++++++++++---- .../java/uta/cse3310/UserInterfaceTest.java | 5 ++- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/test/java/uta/cse3310/GameLogicTest.java b/src/test/java/uta/cse3310/GameLogicTest.java index f99ee5e..12cab80 100644 --- a/src/test/java/uta/cse3310/GameLogicTest.java +++ b/src/test/java/uta/cse3310/GameLogicTest.java @@ -1,17 +1,49 @@ package uta.cse3310; import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + import org.junit.Before; import org.junit.Test; public class GameLogicTest { private GameLogic gameLogic; + private List players; + private Broadcast mockBroadcast; + + + class MockBroadcast implements Broadcast { + List messages = new ArrayList<>(); + + @Override + public void broadcast(String message) { + messages.add(message); + } + } @Before public void setUp() { - PlayerType player = new PlayerType("Player1", "Red", PlayerType.Status.Waiting); - gameLogic = new GameLogic(player); + players = new ArrayList<>(); + players.add(new PlayerType("Player1", "Blue", PlayerType.Status.Waiting)); // Assuming PlayerType constructor requires a status + mockBroadcast = new MockBroadcast(); + gameLogic = new GameLogic(players, mockBroadcast); + gameLogic.validWords.add("word"); + } + + @Test + public void testIsValidWord() { + // Assuming isValidWord checks something about the first player + assertTrue(gameLogic.isValidWord("word")); + assertFalse(gameLogic.isValidWord("nonexistent")); + } + + @Test + public void testGameStart() { + gameLogic.startGame(); + assertTrue(((MockBroadcast) mockBroadcast).messages.contains("Game starts now!")); } @Test @@ -53,11 +85,6 @@ public void testCalculateFillerPercentage() { assertTrue(fillerPercentage >= 0 && fillerPercentage <= 100); } - @Test - public void testIsValidWord() { - assertTrue(gameLogic.isValidWord("RedWord")); - assertFalse(gameLogic.isValidWord("BlueWord")); - } @Test public void testCheckColumns() { diff --git a/src/test/java/uta/cse3310/UserInterfaceTest.java b/src/test/java/uta/cse3310/UserInterfaceTest.java index ba15d19..a9f744c 100644 --- a/src/test/java/uta/cse3310/UserInterfaceTest.java +++ b/src/test/java/uta/cse3310/UserInterfaceTest.java @@ -11,7 +11,10 @@ public void testGetReadyUp() { UserInterface userInterface = new UserInterface(true); // Verify that getReadyUp returns true - assertTrue(userInterface.getReadyUp()); + assertTrue(userInterface.getReadyUp()); // Checks if readyUp is true + + userInterface.setReadyUp(false); + assertFalse(userInterface.getReadyUp()); } @Test