introduce bitloops

This commit is contained in:
mike
2026-01-20 01:35:34 +01:00
parent 5678af332e
commit 7e5e363a3e
7 changed files with 74 additions and 51 deletions

View File

@@ -48,4 +48,46 @@ public class CornerClueTest {
assertEquals(1, slots.length);
assertEquals(4, Masker.Slot.dir(slots[0].key()));
}
@Test
void testCornerDownLeftSlot() {
Clues clues = Clues.createEmpty();
// Clue op (0,1), type 5 (Corner Down Left)
// Should result in word starting at (0,0) going down.
int idx = Masker.offset(0, 1);
clues.setClueLo(1L << idx, (byte)5);
assertEquals(5, clues.getDir(idx));
// Controleer of forEachSlot het slot vindt
final boolean[] found = {false};
clues.forEachSlot((key, lo, hi) -> {
if (Masker.Slot.dir(key) == 5) {
found[0] = true;
// Woord zou moeten starten op (0,0)
int startIdx = Masker.offset(0, 0);
assertTrue((lo & (1L << startIdx)) != 0, "Slot should start at (0,0)");
// En omlaag gaan
int secondIdx = Masker.offset(1, 0);
assertTrue((lo & (1L << secondIdx)) != 0, "Slot should continue to (1,0)");
// Lengte van het slot zou 8 moeten zijn (van rij 0 t/m 7 in kolom 0)
assertEquals(8, Masker.Slot.length(lo, hi));
}
});
assertTrue(found[0], "Corner Down Left slot should be found");
}
@Test
void testCornerDownLeftExtraction() {
Clues clues = Clues.createEmpty();
int idx = Masker.offset(0, 1);
clues.setClueLo(1L << idx, (byte)5);
DictEntry[] dict = DictData.DICT.index();
Slotinfo[] slots = Masker.slots(clues, dict);
assertEquals(1, slots.length);
assertEquals(5, Masker.Slot.dir(slots[0].key()));
}
}

View File

@@ -50,7 +50,7 @@ public class ExportFormatTest {
var fillResult = new FillResult(true, 0, 0, 0, 0, new FillStats());
var puzzleResult = new PuzzleResult(new Clued(clues), grid, new Slotinfo[]{
new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null)
new Slotinfo(key, lo, 0L, 0, new Assign(TEST), null, 0)
}, fillResult);
var rewards = new Rewards(10, 5, 1);

View File

@@ -107,6 +107,8 @@ public class MainTest {
assertTrue(Masker.Slot.horiz(3)); // Left
assertFalse(Masker.Slot.horiz(0)); // Down
assertFalse(Masker.Slot.horiz(2)); // Up
assertFalse(Masker.Slot.horiz(4)); //
assertFalse(Masker.Slot.horiz(5)); //
}
@Test
public void testGridBasics() {

View File

@@ -18,8 +18,8 @@ import static puzzle.SwedishGeneratorTest.Idx.IDX_0_0;
public class SwedishGeneratorTest {
public static final char C_DASH = '\0';
public static final byte DASH = (byte) C_DASH;
public static final char C_DASH = '\0';
public static final byte DASH = (byte) C_DASH;
static Grid createEmpty() { return new Grid(new byte[SIZE], X, X); }
record Context(long[] bitset) {
@@ -29,19 +29,19 @@ public class SwedishGeneratorTest {
public static Context get() { return CTX.get(); }
}
static final long TEST = Lemma.from("TEST");
static final long IN = Lemma.from("IN");
static final long INER = Lemma.from("INER");
static final long INEREN = Lemma.from("INEREN");
static final long INERENA = Lemma.from("INERENA");
static final long INERENAE = Lemma.from("INERENAE");
static final long APPLE = Lemma.from("APPLE");
static final long EXE = Lemma.from("AXE");
static final long ABC = Lemma.from("ABC");
static final long ABD = Lemma.from("ABD");
static final long AZ = Lemma.from("AZ");
static final long AB = Lemma.from("AB");
static final long[] WORDS = new long[]{
static final long TEST = Lemma.from("TEST");
static final long IN = Lemma.from("IN");
static final long INER = Lemma.from("INER");
static final long INEREN = Lemma.from("INEREN");
static final long INERENA = Lemma.from("INERENA");
static final long INERENAE = Lemma.from("INERENAE");
static final long APPLE = Lemma.from("APPLE");
static final long EXE = Lemma.from("AXE");
static final long ABC = Lemma.from("ABC");
static final long ABD = Lemma.from("ABD");
static final long AZ = Lemma.from("AZ");
static final long AB = Lemma.from("AB");
static final long[] WORDS = new long[]{
Lemma.from("AT"),
Lemma.from("CAT"),
Lemma.from("DOGS"),
@@ -196,7 +196,7 @@ public class SwedishGeneratorTest {
assertEquals(val1, rng2.nextU32());
for (var i = 0; i < 100; i++) {
var r = rng.randint(6);
var r = rng.randomClueDir();
assertTrue(r >= 0 && r <= 5);
var f = rng.nextFloat();
assertTrue(f >= 0.0 && f <= 1.0);