Gather data
This commit is contained in:
47
src/test/java/puzzle/SwedishGeneratorTest.java
Normal file
47
src/test/java/puzzle/SwedishGeneratorTest.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package puzzle;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import puzzle.SwedishGenerator.Grid;
|
||||
import puzzle.SwedishGenerator.Slot;
|
||||
import java.util.ArrayList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class SwedishGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testExtractSlots() {
|
||||
SwedishGenerator generator = new SwedishGenerator(3, 3);
|
||||
Grid grid = generator.makeEmptyGrid();
|
||||
|
||||
// Set up digits on the grid to create slots.
|
||||
for (int r = 0; r < 3; r++) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
if ((r + c) % 2 == 0) {
|
||||
grid.setCharAt(r, c, '1');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set up letter cells around digits to form valid slots.
|
||||
int[][] directions = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 } };
|
||||
|
||||
for (int r = 0; r < 3; r++) {
|
||||
for (int c = 0; c < 3; c++) {
|
||||
if (grid.isDigitAt(r, c)) {
|
||||
int dr = directions[grid.digitAt(r, c)][0];
|
||||
int dc = directions[grid.digitAt(r, c)][1];
|
||||
|
||||
int rr = r + dr;
|
||||
int cc = c + dc;
|
||||
|
||||
if (rr >= 0 && rr < generator.H() && cc >= 0 && cc < generator.W())
|
||||
grid.setCharAt(rr, cc, 'A');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check the extractSlots method.
|
||||
ArrayList<Slot> slots = generator.extractSlots(grid);
|
||||
assertEquals(3, slots.size());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user