Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
2onefan2 committed Apr 29, 2024
1 parent f6aa694 commit eb8ef37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/main/java/uta/cse3310/GridField.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uta.cse3310;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class GridField {
Expand Down Expand Up @@ -94,6 +93,8 @@ public void placeRandomWords() {
}
if (wordPlaced) {
remainingWords.remove(word); // Remove the word from remainingWords if successfully placed
} else {
System.out.println("Failed to place word: " + word); // Print a message if the word cannot be placed
}
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/uta/cse3310/GridFieldTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class GridFieldTest {
public void testGenerateGrid() {
GridField gridField = new GridField(new ArrayList<>());
gridField.generateGrid(5);
assertNotNull("Grid should not be null", gridField.getGrid());
assertEquals("Incorrect number of rows", 5, gridField.getGrid().length);
assertEquals("Incorrect number of columns", 5, gridField.getGrid()[0].length);
assertNotNull(gridField.getGrid());
assertEquals(5, gridField.getGrid().length);
assertEquals(5, gridField.getGrid()[0].length);
}

@Test
Expand All @@ -24,8 +24,8 @@ public void testCheckWord() {
wordList.add("HELLO");
wordList.add("WORLD");
GridField gridField = new GridField(wordList);
assertTrue("HELLO should be present", gridField.checkWord("HELLO"));
assertFalse("GOODBYE should not be present", gridField.checkWord("GOODBYE"));
assertTrue(gridField.checkWord("HELLO"));
assertFalse(gridField.checkWord("GOODBYE"));
}

@Test
Expand All @@ -34,7 +34,7 @@ public void testGetRemainingWords() {
wordList.add("HELLO");
wordList.add("WORLD");
GridField gridField = new GridField(wordList);
assertEquals("Incorrect number of remaining words", 2, gridField.getRemainingWords());
assertEquals(2, gridField.getRemainingWords());
}

@Test
Expand All @@ -44,16 +44,16 @@ public void testRevealWord() {
wordList.add("WORLD");
GridField gridField = new GridField(wordList);
gridField.revealWord("HELLO");
assertEquals("Incorrect number of remaining words after revealing", 1, gridField.getRemainingWords());
assertEquals(1, gridField.getRemainingWords());
}

@Test
public void testAddWord() {
ArrayList<String> wordList = new ArrayList<>();
GridField gridField = new GridField(wordList);
gridField.addWord("HELLO", 0, 0, Direction.Directions.HORIZONTAL); // Adjusted here
assertEquals("Incorrect number of remaining words after adding", 1, gridField.getRemainingWords());
assertTrue("HELLO should be present after adding", gridField.checkWord("HELLO"));
assertEquals(1, gridField.getRemainingWords());
assertTrue(gridField.checkWord("HELLO"));
}

@Test
Expand All @@ -71,15 +71,15 @@ public void testPlaceRandomWords() {
char[][] grid = gridField.getGrid();

// Check if the grid is not null
assertNotNull("Grid should not be null", grid);
assertNotNull(grid);

// Check if the grid size is within a reasonable range
assertTrue("Incorrect number of rows", grid.length >= 5 && grid.length <= 10);
assertTrue("Incorrect number of columns", grid[0].length >= 5 && grid[0].length <= 10);
assertTrue(grid.length >= 5 && grid.length <= 10);
assertTrue(grid[0].length >= 5 && grid[0].length <= 10);

// Check if all words from the word list are placed on the grid
for (String word : wordList) {
assertTrue("Word " + word + " should be present on the grid", gridField.checkWord(word));
assertTrue(gridField.checkWord(word));
}
}
}

0 comments on commit eb8ef37

Please sign in to comment.