introduce bitloops
This commit is contained in:
@@ -7,45 +7,23 @@ import puzzle.Export.Clue;
|
||||
import puzzle.Masker.Clues;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static precomp.Const9x8.OFF_0_0;
|
||||
import static precomp.Const9x8.OFF_0_1;
|
||||
import static precomp.Const9x8.OFF_1_0;
|
||||
import static precomp.Const9x8.OFF_1_1;
|
||||
import static puzzle.CornerClueTest.Cell.r0c1d5;
|
||||
import static puzzle.CornerClueTest.Cell.r0c0d4;
|
||||
import static precomp.Const9x8.*;
|
||||
import static precomp.Const9x8.Cell.*;
|
||||
|
||||
public class CornerClueTest {
|
||||
|
||||
enum Cell {
|
||||
r0c0d4(Clue.LEFT_TOP4, OFF_0_0),
|
||||
r0c1d5(Clue.RIGHT_TOP5, OFF_0_1);
|
||||
final public byte d;
|
||||
final public long mask;
|
||||
final public int index;
|
||||
Cell(Clue d, int off) {
|
||||
this.d = d.dir;
|
||||
this.mask = 1L << off;
|
||||
this.index = off;
|
||||
}
|
||||
public Clues attach(Clues c) {
|
||||
c.setClueLo(mask, d);
|
||||
return c;
|
||||
}
|
||||
public Clues attach() { return attach(Clues.createEmpty()); }
|
||||
public int dir(Clues clues) { return clues.getDir(index); }
|
||||
}
|
||||
@Test
|
||||
void testCornerDownSlot() {
|
||||
|
||||
var clues = r0c0d4.attach();
|
||||
var clues = Clues.createEmpty().setClue(r0c0d4);
|
||||
// Clue op (0,0), type 4 (Corner Down)
|
||||
|
||||
assertEquals(Clue.LEFT_TOP4.dir, r0c0d4.dir(clues));
|
||||
assertEquals(r0c0d4.d, clues.getDir(r0c0d4.index));
|
||||
|
||||
// Controleer of forEachSlot het slot vindt
|
||||
final var found = new boolean[]{ false };
|
||||
clues.forEachSlot((key, lo, hi) -> {
|
||||
if (Masker.Slot.dir(key) == 4) {
|
||||
if (key == r0c0d4.slotKey) {
|
||||
found[0] = true;
|
||||
// Woord zou moeten starten op (0,1)
|
||||
assertTrue((lo & (1L << OFF_0_1)) != 0, "Slot should start at (0,1)");
|
||||
@@ -61,21 +39,21 @@ public class CornerClueTest {
|
||||
|
||||
@Test
|
||||
void testCornerDownExtraction() {
|
||||
var slots = Masker.slots(r0c0d4.attach(), DictData.DICT.index());
|
||||
var slots = Masker.slots(Clues.createEmpty().setClue(r0c0d4), DictData.DICT.index());
|
||||
assertEquals(1, slots.length);
|
||||
assertEquals(4, Masker.Slot.dir(slots[0].key()));
|
||||
assertEquals(r0c0d4.d, Masker.Slot.dir(slots[0].key()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCornerDownLeftSlot() {
|
||||
var clues = r0c1d5.attach();
|
||||
var clues = Clues.createEmpty().setClue(r0c1d5);
|
||||
|
||||
assertEquals(Clue.RIGHT_TOP5.dir, r0c1d5.dir(clues));
|
||||
assertEquals(r0c1d5.d, clues.getDir(r0c1d5.index));
|
||||
|
||||
// Controleer of forEachSlot het slot vindt
|
||||
final var found = new boolean[]{ false };
|
||||
clues.forEachSlot((key, lo, hi) -> {
|
||||
if (Masker.Slot.dir(key) == 5) {
|
||||
if (key == r0c1d5.slotKey) {
|
||||
found[0] = true;
|
||||
// Woord zou moeten starten op (0,0)
|
||||
assertTrue((lo & (1L << OFF_0_0)) != 0, "Slot should start at (0,0)");
|
||||
@@ -91,9 +69,9 @@ public class CornerClueTest {
|
||||
|
||||
@Test
|
||||
void testCornerDownLeftExtraction() {
|
||||
var slots = Masker.slots(r0c1d5.attach(), DictData.DICT.index());
|
||||
var slots = Masker.slots(Clues.createEmpty().setClue(r0c1d5), DictData.DICT.index());
|
||||
|
||||
assertEquals(1, slots.length);
|
||||
assertEquals(Clue.RIGHT_TOP5.dir, Masker.Slot.dir(slots[0].key()));
|
||||
assertEquals(r0c1d5.d, Masker.Slot.dir(slots[0].key()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user