Gather data

This commit is contained in:
mike
2026-01-07 00:30:47 +01:00
parent 5c5462085c
commit 243935e73a
4 changed files with 55 additions and 67 deletions

View File

@@ -5,6 +5,7 @@ import puzzle.SwedishGenerator.Grid;
import puzzle.SwedishGenerator.Slot;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SwedishGeneratorTest {
@@ -14,34 +15,18 @@ class SwedishGeneratorTest {
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');
}
}
}
// '2' (right) at (0,0) -> slot at (0,1), (0,2)
grid.setCharAt(0, 0, '2');
grid.setCharAt(0, 1, 'A');
grid.setCharAt(0, 2, 'B');
// 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());
assertEquals(1, slots.size());
Slot s = slots.get(0);
assertEquals(2, s.len());
assertEquals(0, s.r(0));
assertEquals(1, s.c(0));
assertEquals(0, s.r(1));
assertEquals(2, s.c(1));
}
}