diff --git a/src/main/java/uta/cse3310/GridField.java b/src/main/java/uta/cse3310/GridField.java index afe8027..0ecffe6 100644 --- a/src/main/java/uta/cse3310/GridField.java +++ b/src/main/java/uta/cse3310/GridField.java @@ -1,7 +1,6 @@ package uta.cse3310; import java.util.ArrayList; -import java.util.Arrays; import java.util.Random; public class GridField { @@ -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 } } } diff --git a/src/test/java/uta/cse3310/GridFieldTest.java b/src/test/java/uta/cse3310/GridFieldTest.java index 3b1f617..8dac998 100644 --- a/src/test/java/uta/cse3310/GridFieldTest.java +++ b/src/test/java/uta/cse3310/GridFieldTest.java @@ -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 @@ -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 @@ -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 @@ -44,7 +44,7 @@ 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 @@ -52,8 +52,8 @@ public void testAddWord() { ArrayList 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 @@ -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)); } } }