Gather data
This commit is contained in:
@@ -502,7 +502,7 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
return penalty;
|
return penalty;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwedishGenerator.Grid randomMask(SwedishGenerator.Rng rng) {
|
Grid randomMask(Rng rng) {
|
||||||
var g = makeEmptyGrid();
|
var g = makeEmptyGrid();
|
||||||
int placed = 0, guard = 0;
|
int placed = 0, guard = 0;
|
||||||
|
|
||||||
@@ -683,7 +683,6 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
}
|
}
|
||||||
// ---------------- Fill (CSP) ----------------
|
// ---------------- Fill (CSP) ----------------
|
||||||
|
|
||||||
@Data
|
|
||||||
public static final class FillStats {
|
public static final class FillStats {
|
||||||
|
|
||||||
public long nodes;
|
public long nodes;
|
||||||
@@ -692,11 +691,11 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
public int lastMRV;
|
public int lastMRV;
|
||||||
}
|
}
|
||||||
|
|
||||||
record Pick(SwedishGenerator.Slot slot, SwedishGenerator.CandidateInfo info, boolean done) { }
|
record Pick(Slot slot, CandidateInfo info, boolean done) { }
|
||||||
|
|
||||||
public static record FillResult(boolean ok,
|
public static record FillResult(boolean ok,
|
||||||
Gridded grid,
|
Gridded grid,
|
||||||
HashMap<Integer, SwedishGenerator.Lemma> clueMap,
|
HashMap<Integer, Lemma> clueMap,
|
||||||
FillStats stats,
|
FillStats stats,
|
||||||
double simplicity) {
|
double simplicity) {
|
||||||
|
|
||||||
@@ -744,7 +743,7 @@ public record SwedishGenerator(int[] buff) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FillResult fillMask(Rng rng, Grid mask, SwedishGenerator.DictEntry[] dictIndex,
|
public FillResult fillMask(Rng rng, Grid mask, DictEntry[] dictIndex,
|
||||||
int logEveryMs, int timeLimitMs, boolean verbose) {
|
int logEveryMs, int timeLimitMs, boolean verbose) {
|
||||||
boolean multiThreaded = Thread.currentThread().getName().contains("pool");
|
boolean multiThreaded = Thread.currentThread().getName().contains("pool");
|
||||||
var grid = mask.deepCopyGrid();
|
var grid = mask.deepCopyGrid();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static puzzle.SwedishGenerator.*;
|
||||||
import static puzzle.SwedishGenerator.DASH;
|
import static puzzle.SwedishGenerator.DASH;
|
||||||
|
|
||||||
public class MainTest {
|
public class MainTest {
|
||||||
@@ -23,7 +24,7 @@ public class MainTest {
|
|||||||
@Test
|
@Test
|
||||||
void testExtractSlots() {
|
void testExtractSlots() {
|
||||||
var generator = new SwedishGenerator();
|
var generator = new SwedishGenerator();
|
||||||
var grid = SwedishGenerator.makeEmptyGrid();
|
var grid = makeEmptyGrid();
|
||||||
|
|
||||||
// Set up digits on the grid to create slots.
|
// Set up digits on the grid to create slots.
|
||||||
// '2' (right) at (0,0) -> slot at (0,1), (0,2)
|
// '2' (right) at (0,0) -> slot at (0,1), (0,2)
|
||||||
@@ -35,19 +36,19 @@ public class MainTest {
|
|||||||
assertEquals(1, slots.size());
|
assertEquals(1, slots.size());
|
||||||
var s = slots.get(0);
|
var s = slots.get(0);
|
||||||
assertEquals(8, s.len());
|
assertEquals(8, s.len());
|
||||||
assertEquals(0, SwedishGenerator.Grid.r(s.pos(0)));
|
assertEquals(0, Grid.r(s.pos(0)));
|
||||||
assertEquals(1, SwedishGenerator.Grid.c(s.pos(0)));
|
assertEquals(1, Grid.c(s.pos(0)));
|
||||||
assertEquals(0, SwedishGenerator.Grid.r(s.pos(1)));
|
assertEquals(0, Grid.r(s.pos(1)));
|
||||||
assertEquals(2, SwedishGenerator.Grid.c(s.pos(1)));
|
assertEquals(2, Grid.c(s.pos(1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testStaticSlotMethods() {
|
void testStaticSlotMethods() {
|
||||||
// Test static offset extraction
|
// Test static offset extraction
|
||||||
// packedPos: offset(1, 1) at index 0, offset(2, 2) at index 1
|
// packedPos: offset(1, 1) at index 0, offset(2, 2) at index 1
|
||||||
var packedPos = ((long) SwedishGenerator.Grid.offset(1, 1)) | (((long) SwedishGenerator.Grid.offset(2, 2)) << 7);
|
var packedPos = ((long) Grid.offset(1, 1)) | (((long) Grid.offset(2, 2)) << 7);
|
||||||
assertEquals(SwedishGenerator.Grid.offset(1, 1), Slot.offset(packedPos, 0));
|
assertEquals(Grid.offset(1, 1), Slot.offset(packedPos, 0));
|
||||||
assertEquals(SwedishGenerator.Grid.offset(2, 2), Slot.offset(packedPos, 1));
|
assertEquals(Grid.offset(2, 2), Slot.offset(packedPos, 1));
|
||||||
|
|
||||||
// Test static horiz
|
// Test static horiz
|
||||||
// dir 2 (right) is horizontal
|
// dir 2 (right) is horizontal
|
||||||
@@ -59,15 +60,15 @@ public class MainTest {
|
|||||||
@Test
|
@Test
|
||||||
void testForEachSlot() {
|
void testForEachSlot() {
|
||||||
var generator = new SwedishGenerator();
|
var generator = new SwedishGenerator();
|
||||||
var grid = SwedishGenerator.makeEmptyGrid();
|
var grid = makeEmptyGrid();
|
||||||
grid.setCharAt(0, 0, '2'); // right
|
grid.setCharAt(0, 0, '2'); // right
|
||||||
|
|
||||||
var count = new AtomicInteger(0);
|
var count = new AtomicInteger(0);
|
||||||
generator.forEachSlot(grid, (key, packedPos, len) -> {
|
generator.forEachSlot(grid, (key, packedPos, len) -> {
|
||||||
count.incrementAndGet();
|
count.incrementAndGet();
|
||||||
assertEquals(8, len);
|
assertEquals(8, len);
|
||||||
assertEquals(0, SwedishGenerator.Grid.r(Slot.offset(packedPos, 0)));
|
assertEquals(0, Grid.r(Slot.offset(packedPos, 0)));
|
||||||
assertEquals(1, SwedishGenerator.Grid.c(Slot.offset(packedPos, 0)));
|
assertEquals(1, Grid.c(Slot.offset(packedPos, 0)));
|
||||||
});
|
});
|
||||||
assertEquals(1, count.get());
|
assertEquals(1, count.get());
|
||||||
}
|
}
|
||||||
@@ -81,7 +82,7 @@ public class MainTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testGridBasics() {
|
public void testGridBasics() {
|
||||||
var grid = SwedishGenerator.makeEmptyGrid();
|
var grid = makeEmptyGrid();
|
||||||
// Initialize with #
|
// Initialize with #
|
||||||
for (int r = 0; r < 3; r++) {
|
for (int r = 0; r < 3; r++) {
|
||||||
for (int c = 0; c < 4; c++) {
|
for (int c = 0; c < 4; c++) {
|
||||||
@@ -120,7 +121,7 @@ public class MainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGridDeepCopy() {
|
public void testGridDeepCopy() {
|
||||||
var grid = SwedishGenerator.makeEmptyGrid();
|
var grid = makeEmptyGrid();
|
||||||
grid.setCharAt(0, 0, 'A');
|
grid.setCharAt(0, 0, 'A');
|
||||||
grid.setCharAt(0, 1, 'B');
|
grid.setCharAt(0, 1, 'B');
|
||||||
grid.setCharAt(1, 0, 'C');
|
grid.setCharAt(1, 0, 'C');
|
||||||
@@ -136,7 +137,7 @@ public class MainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMini() {
|
public void testMini() {
|
||||||
var grid = SwedishGenerator.makeEmptyGrid();
|
var grid = makeEmptyGrid();
|
||||||
grid.setCharAt(1, 1, '1');
|
grid.setCharAt(1, 1, '1');
|
||||||
Assertions.assertTrue(grid.isDigitAt(1, 1));
|
Assertions.assertTrue(grid.isDigitAt(1, 1));
|
||||||
}
|
}
|
||||||
@@ -153,7 +154,7 @@ public class MainTest {
|
|||||||
opts.tries = 1;
|
opts.tries = 1;
|
||||||
opts.verbose = false;
|
opts.verbose = false;
|
||||||
|
|
||||||
var dict = SwedishGenerator.loadWords(opts.wordsPath);
|
var dict = loadWords(opts.wordsPath);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PuzzleResult res = null;
|
PuzzleResult res = null;
|
||||||
@@ -185,12 +186,12 @@ public class MainTest {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
public void testIsLetterA() {
|
public void testIsLetterA() {
|
||||||
assertTrue(SwedishGenerator.isLetter((byte) 'A'));
|
assertTrue(isLetter((byte) 'A'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsLetterZ() {
|
public void testIsLetterZ() {
|
||||||
assertTrue(SwedishGenerator.isLetter((byte) 'Z'));
|
assertTrue(isLetter((byte) 'Z'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user