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

@@ -102,22 +102,22 @@ public class MainTest {
// But SwedishGenerator.loadWords(path) is what we have.
// Let's try to load a real one or a small subset if possible.
var dict = new Dict(new Lemma[]{
new Lemma(0, "NU", 1, 100, "NU"),
new Lemma(1, "ET", 2, 100, "ET"),
new Lemma(2, "NUT", 3, 1001, "NUT"),
new Lemma(3, "ETE", 4, 100, "ETE"),
new Lemma(4, "IK", 5, 100, "IK"),
new Lemma(5, "IN", 6, 100, "IN"),
new Lemma(6, "AU", 7, 100, "AU"),
new Lemma(7, "JE", 8, 100, "JE"),
new Lemma(8, "AI", 9, 100, "AI"),
new Lemma(9, "NA", 10, 100, "NA"),
new Lemma(10, "AF", 11, 100, "AF"),
new Lemma(11, "AL", 14, 1001, "AL"),
new Lemma(12, "EA", 15, 100, "EA"),
new Lemma(13, "AV", 18, 100, "AV"),
new Lemma(14, "IL", 19, 100, "IL"),
new Lemma(15, "EN", 22, 100, "EN")
new Lemma(0, "NU", 1, "NU"),
new Lemma(1, "ET", 2, "ET"),
new Lemma(2, "NUT", 3, "NUT"),
new Lemma(3, "ETE", 4, "ETE"),
new Lemma(4, "IK", 5, "IK"),
new Lemma(5, "IN", 6, "IN"),
new Lemma(6, "AU", 7, "AU"),
new Lemma(7, "JE", 8, "JE"),
new Lemma(8, "AI", 9, "AI"),
new Lemma(9, "NA", 10, "NA"),
new Lemma(10, "AF", 11, "AF"),
new Lemma(11, "AL", 14, "AL"),
new Lemma(12, "EA", 15, "EA"),
new Lemma(13, "AV", 18, "AV"),
new Lemma(14, "IL", 19, "IL"),
new Lemma(15, "EN", 22, "EN")
});
// Act

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