introduce bitloops
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package puzzle;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import puzzle.Export.Clue;
|
||||
import puzzle.Masker.Clues;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -8,17 +11,36 @@ 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;
|
||||
|
||||
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 = Clues.createEmpty();
|
||||
// Clue op (0,0), type 4 (Corner Down)
|
||||
var idx = OFF_0_0;
|
||||
clues.setClueLo(1L << idx, (byte) 4);
|
||||
|
||||
assertEquals(4, clues.getDir(idx));
|
||||
var clues = r0c0d4.attach();
|
||||
// Clue op (0,0), type 4 (Corner Down)
|
||||
|
||||
assertEquals(Clue.LEFT_TOP4.dir, r0c0d4.dir(clues));
|
||||
|
||||
// Controleer of forEachSlot het slot vindt
|
||||
final var found = new boolean[]{ false };
|
||||
@@ -39,25 +61,16 @@ public class CornerClueTest {
|
||||
|
||||
@Test
|
||||
void testCornerDownExtraction() {
|
||||
var clues = Clues.createEmpty();
|
||||
clues.setClueLo(1L << OFF_0_0, (byte) 4);
|
||||
|
||||
var dict = DictData.DICT.index();
|
||||
var slots = Masker.slots(clues, dict);
|
||||
|
||||
var slots = Masker.slots(r0c0d4.attach(), DictData.DICT.index());
|
||||
assertEquals(1, slots.length);
|
||||
assertEquals(4, Masker.Slot.dir(slots[0].key()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCornerDownLeftSlot() {
|
||||
var clues = Clues.createEmpty();
|
||||
// Clue op (0,1), type 5 (Corner Down Left)
|
||||
// Should result in word starting at (0,0) going down.
|
||||
var idx = OFF_0_1;
|
||||
clues.setClueLo(1L << idx, (byte) 5);
|
||||
var clues = r0c1d5.attach();
|
||||
|
||||
assertEquals(5, clues.getDir(idx));
|
||||
assertEquals(Clue.RIGHT_TOP5.dir, r0c1d5.dir(clues));
|
||||
|
||||
// Controleer of forEachSlot het slot vindt
|
||||
final var found = new boolean[]{ false };
|
||||
@@ -78,13 +91,9 @@ public class CornerClueTest {
|
||||
|
||||
@Test
|
||||
void testCornerDownLeftExtraction() {
|
||||
var clues = Clues.createEmpty();
|
||||
clues.setClueLo(1L << OFF_0_1, (byte) 5);
|
||||
|
||||
var dict = DictData.DICT.index();
|
||||
var slots = Masker.slots(clues, dict);
|
||||
var slots = Masker.slots(r0c1d5.attach(), DictData.DICT.index());
|
||||
|
||||
assertEquals(1, slots.length);
|
||||
assertEquals(5, Masker.Slot.dir(slots[0].key()));
|
||||
assertEquals(Clue.RIGHT_TOP5.dir, Masker.Slot.dir(slots[0].key()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user