From dd6c1bd9def3bd1a90bbb09ec7994b806e3fc355 Mon Sep 17 00:00:00 2001 From: Andy Date: Mon, 5 Aug 2024 22:17:08 -0500 Subject: [PATCH] Changes to fix new tests to compile --- src/main/java/uta/cse3310/Player.java | 8 ++++++ src/main/java/uta/cse3310/Round.java | 4 +-- src/test/java/uta/cse3310/PlayerTest.java | 28 +++++++++++++------- src/test/java/uta/cse3310/RoundTest.java | 31 ++++++++++++++--------- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/src/main/java/uta/cse3310/Player.java b/src/main/java/uta/cse3310/Player.java index be5c936..6762e68 100644 --- a/src/main/java/uta/cse3310/Player.java +++ b/src/main/java/uta/cse3310/Player.java @@ -54,5 +54,13 @@ public boolean isStatusPlayer() { public void setStatusPlayer(boolean statusPlayer) { this.statusPlayer = statusPlayer; } + + public void setInventory(String inventory) { + this.inventory = inventory; + } + + public String getInventory() { + return inventory; + } } diff --git a/src/main/java/uta/cse3310/Round.java b/src/main/java/uta/cse3310/Round.java index c1200a5..d683bdf 100644 --- a/src/main/java/uta/cse3310/Round.java +++ b/src/main/java/uta/cse3310/Round.java @@ -20,9 +20,9 @@ public class Round { private LocalDateTime endTime; private int score; private String status; - private List words; private String currentWord; private Random random; + public List words; // Constructor public Round(int roundNumber) { @@ -56,7 +56,7 @@ public void startRound() { } // Choose a random word from the list - private void chooseRandomWord() { + public void chooseRandomWord() { if (words != null && !words.isEmpty()) { currentWord = words.get(random.nextInt(words.size())); System.out.println("Chosen Word: " + currentWord); // For debugging purposes diff --git a/src/test/java/uta/cse3310/PlayerTest.java b/src/test/java/uta/cse3310/PlayerTest.java index f6bf2e8..a6e3add 100644 --- a/src/test/java/uta/cse3310/PlayerTest.java +++ b/src/test/java/uta/cse3310/PlayerTest.java @@ -1,11 +1,26 @@ package uta.cse3310; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; -public class PlayerTest { +public class PlayerTest extends TestCase{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public PlayerTest(String testName) { + super(testName); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(PlayerTest.class); + } - @Test public void testPlayerInitialization() { Player player = new Player("John Doe", 1); @@ -16,7 +31,6 @@ public void testPlayerInitialization() { assertEquals("", player.getInventory()); // Updated to reflect empty inventory } - @Test public void testSetPlayerName() { Player player = new Player("John Doe", 1); player.setPlayerName("Jane Doe"); @@ -24,7 +38,6 @@ public void testSetPlayerName() { assertEquals("Jane Doe", player.getPlayerName()); } - @Test public void testSetPlayerID() { Player player = new Player("John Doe", 1); player.setPlayerID(2); @@ -32,7 +45,6 @@ public void testSetPlayerID() { assertEquals(2, player.getPlayerID()); } - @Test public void testSetPoints() { Player player = new Player("John Doe", 1); player.setPoints(100); @@ -40,7 +52,6 @@ public void testSetPoints() { assertEquals(100, player.getPoints()); } - @Test public void testSetStatusPlayer() { Player player = new Player("John Doe", 1); player.setStatusPlayer(true); // Updated to reflect setStatusPlayer @@ -48,7 +59,6 @@ public void testSetStatusPlayer() { assertTrue(player.getStatus()); // Updated to reflect getStatus } - @Test public void testSetInventory() { Player player = new Player("John Doe", 1); player.setInventory("sword"); diff --git a/src/test/java/uta/cse3310/RoundTest.java b/src/test/java/uta/cse3310/RoundTest.java index 31a2056..faabb5b 100644 --- a/src/test/java/uta/cse3310/RoundTest.java +++ b/src/test/java/uta/cse3310/RoundTest.java @@ -3,23 +3,36 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.Arrays; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; -public class RoundTest { +public class RoundTest extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public RoundTest(String testName) { + super(testName); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite(RoundTest.class); + } private Round round; private final String testFilePath = "src/test/resources/test_words.txt"; // Update the path to your test file - @BeforeEach public void setUp() { round = new Round(1); // Mocking loadWordsFromFile round.words = Arrays.asList("apple", "banana", "cherry"); } - @Test public void testRoundInitialization() { assertEquals(1, round.getRoundNumber()); assertNull(round.getStartTime()); @@ -28,7 +41,6 @@ public void testRoundInitialization() { assertEquals("not started", round.getStatus()); } - @Test public void testStartRound() { round.startRound(); assertNotNull(round.getStartTime()); @@ -37,7 +49,6 @@ public void testStartRound() { assertTrue(round.words.contains(round.getCurrentWord())); } - @Test public void testChooseRandomWord() { round.startRound(); String firstWord = round.getCurrentWord(); @@ -50,7 +61,6 @@ public void testChooseRandomWord() { assertTrue(round.words.contains(secondWord)); } - @Test public void testCheckGuess() { round.startRound(); String chosenWord = round.getCurrentWord(); @@ -58,7 +68,6 @@ public void testCheckGuess() { assertFalse(round.checkGuess(chosenWord + "wrong")); } - @Test public void testEndRound() { round.startRound(); round.endRound(); @@ -67,14 +76,12 @@ public void testEndRound() { assertTrue(round.getScore() >= 0); } - @Test public void testCalculateScore() { round.setStartTime(LocalDateTime.now().minusSeconds(5)); round.setEndTime(LocalDateTime.now()); assertEquals(5, round.calculateScore()); } - @Test public void testRoundFlow() { round.startRound(); assertEquals("in progress", round.getStatus());