Gather data

This commit is contained in:
mike
2026-01-06 22:43:45 +01:00
parent 3014571ba3
commit 4085db80f7
4 changed files with 88 additions and 49 deletions

View 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());
}
}