Skip to content

Commit

Permalink
Changes to fix new tests to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-tieu committed Aug 6, 2024
1 parent 4802d4f commit dd6c1bd
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
8 changes: 8 additions & 0 deletions src/main/java/uta/cse3310/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

4 changes: 2 additions & 2 deletions src/main/java/uta/cse3310/Round.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class Round {
private LocalDateTime endTime;
private int score;
private String status;
private List<String> words;
private String currentWord;
private Random random;
public List<String> words;

// Constructor
public Round(int roundNumber) {
Expand Down Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions src/test/java/uta/cse3310/PlayerTest.java
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -16,39 +31,34 @@ 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");

assertEquals("Jane Doe", player.getPlayerName());
}

@Test
public void testSetPlayerID() {
Player player = new Player("John Doe", 1);
player.setPlayerID(2);

assertEquals(2, player.getPlayerID());
}

@Test
public void testSetPoints() {
Player player = new Player("John Doe", 1);
player.setPoints(100);

assertEquals(100, player.getPoints());
}

@Test
public void testSetStatusPlayer() {
Player player = new Player("John Doe", 1);
player.setStatusPlayer(true); // Updated to reflect setStatusPlayer

assertTrue(player.getStatus()); // Updated to reflect getStatus
}

@Test
public void testSetInventory() {
Player player = new Player("John Doe", 1);
player.setInventory("sword");
Expand Down
31 changes: 19 additions & 12 deletions src/test/java/uta/cse3310/RoundTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -28,7 +41,6 @@ public void testRoundInitialization() {
assertEquals("not started", round.getStatus());
}

@Test
public void testStartRound() {
round.startRound();
assertNotNull(round.getStartTime());
Expand All @@ -37,7 +49,6 @@ public void testStartRound() {
assertTrue(round.words.contains(round.getCurrentWord()));
}

@Test
public void testChooseRandomWord() {
round.startRound();
String firstWord = round.getCurrentWord();
Expand All @@ -50,15 +61,13 @@ public void testChooseRandomWord() {
assertTrue(round.words.contains(secondWord));
}

@Test
public void testCheckGuess() {
round.startRound();
String chosenWord = round.getCurrentWord();
assertTrue(round.checkGuess(chosenWord));
assertFalse(round.checkGuess(chosenWord + "wrong"));
}

@Test
public void testEndRound() {
round.startRound();
round.endRound();
Expand All @@ -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());
Expand Down

0 comments on commit dd6c1bd

Please sign in to comment.