Skip to content

Commit 841b147

Browse files
committed
Fix
1 parent b5518e9 commit 841b147

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

src/main/java/com/thealgorithms/backtracking/CrosswordSolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static boolean solveCrossword(char[][] puzzle, List<String> words) {
101101
for (int col = 0; col < puzzle[0].length; col++) {
102102
if (puzzle[row][col] == ' ') {
103103
for (String word : new ArrayList<>(remainingWords)) {
104-
for (boolean vertical : new boolean[]{true, false}) {
104+
for (boolean vertical : new boolean[] {true, false}) {
105105
if (isValid(puzzle, word, row, col, vertical)) {
106106
placeWord(puzzle, word, row, col, vertical);
107107
remainingWords.remove(word);

src/test/java/com/thealgorithms/backtracking/CrosswordSolverTest.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,15 @@ public class CrosswordSolverTest {
1212

1313
@Test
1414
public void testValidPlacement() {
15-
char[][] puzzle = {
16-
{ ' ', ' ', ' ' },
17-
{ ' ', ' ', ' ' },
18-
{ ' ', ' ', ' ' }
19-
};
15+
char[][] puzzle = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
2016
assertTrue(CrosswordSolver.isValid(puzzle, "cat", 0, 0, true));
2117
assertTrue(CrosswordSolver.isValid(puzzle, "dog", 0, 0, false));
2218
assertFalse(CrosswordSolver.isValid(puzzle, "cat", 1, 2, false));
2319
}
2420

2521
@Test
2622
public void testPlaceAndRemoveWord() {
27-
char[][] puzzle = {
28-
{ ' ', ' ', ' ' },
29-
{ ' ', ' ', ' ' },
30-
{ ' ', ' ', ' ' }
31-
};
23+
char[][] puzzle = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
3224
CrosswordSolver.placeWord(puzzle, "cat", 0, 0, true);
3325
assertEquals('c', puzzle[0][0]);
3426
assertEquals('a', puzzle[1][0]);
@@ -42,11 +34,7 @@ public void testPlaceAndRemoveWord() {
4234

4335
@Test
4436
public void testSolveCrossword() {
45-
char[][] puzzle = {
46-
{ ' ', ' ', ' ' },
47-
{ ' ', ' ', ' ' },
48-
{ ' ', ' ', ' ' }
49-
};
37+
char[][] puzzle = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
5038
List<String> words = Arrays.asList("cat", "dog", "car");
5139
assertTrue(CrosswordSolver.solveCrossword(puzzle, words));
5240

@@ -71,11 +59,7 @@ public void testSolveCrossword() {
7159

7260
@Test
7361
public void testNoSolution() {
74-
char[][] puzzle = {
75-
{ ' ', ' ', ' ' },
76-
{ ' ', ' ', ' ' },
77-
{ ' ', ' ', ' ' }
78-
};
62+
char[][] puzzle = {{' ', ' ', ' '}, {' ', ' ', ' '}, {' ', ' ', ' '}};
7963
List<String> words = Arrays.asList("cat", "dog", "elephant"); // 'elephant' is too long for the grid
8064
assertFalse(CrosswordSolver.solveCrossword(puzzle, words));
8165
}

0 commit comments

Comments
 (0)