Skip to content

Commit

Permalink
Text For Game (Kenil Patel)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenil committed Apr 23, 2024
1 parent 088364d commit 4aa88e3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/test/java/uta/cse3310/GameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;

public class GameTest {
private Game game;

@Before
public void setUp() {
game = new Game("testWords.txt", 5, 10);
}

@Test
public void testMatrixInitialization() {
char[][] matrix = game.getMatrix();
for (char[] row : matrix) {
for (char cell : row) {
assertEquals('.', cell);
}
}
}

@Test
public void testWordPlacement() {
game.placeWords();
assertTrue("Expected at least one word placed", game.getNumofWords() > 0);
}

@Test
public void testFillRandom() {
game.fillRandom();
char[][] matrix = game.getMatrix();
boolean hasRandomLetters = false;
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
if (matrix[i][j] != '.') {
hasRandomLetters = true;
assertTrue("Character must be a letter", Character.isLetter(matrix[i][j]));
}
}
}
assertTrue("Matrix should contain random letters", hasRandomLetters);
}

@Test
public void testCheckAnswer() {
assertTrue("Word should be found", game.check_ans(0, 0, 0, 3));
assertFalse("Word should not be found", game.check_ans(0, 0, 5, 5));
}
}
12 changes: 12 additions & 0 deletions src/test/java/uta/cse3310/testWords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apple
grape
computer
mobile
javac
bottle
speaker
monitor
lightbulb
markers
cables
chargers

0 comments on commit 4aa88e3

Please sign in to comment.