introduce bitloops
This commit is contained in:
50
src/test/java/puzzle/CornerClueTest.java
Normal file
50
src/test/java/puzzle/CornerClueTest.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package puzzle;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import puzzle.Masker.Clues;
|
||||
import puzzle.SwedishGenerator.DictEntry;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
|
||||
public class CornerClueTest {
|
||||
@Test
|
||||
void testCornerDownSlot() {
|
||||
Clues clues = Clues.createEmpty();
|
||||
// Clue op (0,0), type 4 (Corner Down)
|
||||
int idx = SwedishGenerator.Grid.offset(0,0);
|
||||
clues.setClueLo(1L << idx, (byte)4);
|
||||
|
||||
assertEquals(4, clues.getDir(idx));
|
||||
|
||||
// Controleer of forEachSlot het slot vindt
|
||||
final boolean[] found = {false};
|
||||
clues.forEachSlot((key, lo, hi) -> {
|
||||
if (Masker.Slot.dir(key) == 4) {
|
||||
found[0] = true;
|
||||
// Woord zou moeten starten op (0,1)
|
||||
int startIdx = SwedishGenerator.Grid.offset(0, 1);
|
||||
assertTrue((lo & (1L << startIdx)) != 0, "Slot should start at (0,1)");
|
||||
// En omlaag gaan
|
||||
int secondIdx = SwedishGenerator.Grid.offset(1, 1);
|
||||
assertTrue((lo & (1L << secondIdx)) != 0, "Slot should continue to (1,1)");
|
||||
|
||||
// Lengte van het slot zou 8 moeten zijn (van rij 0 t/m 7 in kolom 1)
|
||||
assertEquals(8, Masker.Slot.length(lo, hi));
|
||||
}
|
||||
});
|
||||
assertTrue(found[0], "Corner Down slot should be found");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCornerDownExtraction() {
|
||||
Clues clues = Clues.createEmpty();
|
||||
int idx = SwedishGenerator.Grid.offset(0,0);
|
||||
clues.setClueLo(1L << idx, (byte)4);
|
||||
|
||||
DictEntry[] dict = DictData.DICT.index();
|
||||
Slotinfo[] slots = Masker.slots(clues, dict);
|
||||
|
||||
assertEquals(1, slots.length);
|
||||
assertEquals(4, Masker.Slot.dir(slots[0].key()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user