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

@@ -29,35 +29,36 @@ public class MainTest {
grid.setCharAt(r, c, C_DASH);
}
}
// Test set/get
grid.setCharAt(0, 0, 'A');
grid.setCharAt(1, 2, '5');
grid.setCharAt(2, 3, 'Z');
Assertions.assertEquals('A', grid.getCharAt(0, 0));
Assertions.assertEquals('5', grid.getCharAt(1, 2));
Assertions.assertEquals('Z', grid.getCharAt(2, 3));
Assertions.assertEquals(C_DASH, grid.getCharAt(1, 1));
// Test isLetterAt
Assertions.assertTrue(grid.isLetterAt(0, 0));
Assertions.assertFalse(grid.isLetterAt(1, 2));
Assertions.assertTrue(grid.isLetterAt(2, 3));
Assertions.assertFalse(grid.isLetterAt(1, 1));
// Test isDigitAt
Assertions.assertFalse(grid.isDigitAt(0, 0));
Assertions.assertTrue(grid.isDigitAt(1, 2));
Assertions.assertEquals(5, grid.digitAt(1, 2));
Assertions.assertFalse(grid.isDigitAt(2, 3));
Assertions.assertFalse(grid.isDigitAt(1, 1));
// Test isLettercell
Assertions.assertTrue(grid.isLettercell(0, 0)); // 'A' is letter
Assertions.assertFalse(grid.isLettercell(1, 2)); // '5' is digit
Assertions.assertTrue(grid.isLettercell(1, 1)); // '#' is lettercell
}
@Test
public void testGridDeepCopy() {
var grid = new Grid(new byte[2 * 2], 2, 2);
@@ -65,7 +66,7 @@ public class MainTest {
grid.setCharAt(0, 1, 'B');
grid.setCharAt(1, 0, 'C');
grid.setCharAt(1, 1, 'D');
var copy = grid.deepCopyGrid();
Assertions.assertEquals('A', copy.getCharAt(0, 0));
@@ -73,8 +74,7 @@ public class MainTest {
Assertions.assertEquals('X', copy.getCharAt(0, 0));
Assertions.assertEquals('A', grid.getCharAt(0, 0)); // Original should be unchanged
}
@Test
public void testMini() {
var grid = new Grid(new byte[3 * 3], 3, 3);

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