introduce bitloops
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package puzzle;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import puzzle.Export.Clued;
|
||||
@@ -13,13 +12,11 @@ import puzzle.SwedishGenerator.FillResult;
|
||||
import puzzle.SwedishGenerator.Lemma;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
import puzzle.SwedishGeneratorTest.Idx;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static puzzle.ExportFormatTest.Clue.RIGHT;
|
||||
import static puzzle.Export.Clue.LEFT;
|
||||
import static puzzle.Export.Clue.RIGHT;
|
||||
import static puzzle.SwedishGenerator.C;
|
||||
import static puzzle.Masker.Clues;
|
||||
import static puzzle.SwedishGenerator.FillStats;
|
||||
@@ -34,25 +31,6 @@ import static puzzle.SwedishGeneratorTest.TEST;
|
||||
|
||||
public class ExportFormatTest {
|
||||
|
||||
static final byte CLUE_DOWN = 0;
|
||||
static final byte CLUE_RIGHT = 1;
|
||||
static final byte CLUE_UP = 2;
|
||||
static final byte CLUE_LEFT = 3;
|
||||
|
||||
@AllArgsConstructor
|
||||
enum Clue {
|
||||
DOWN(CLUE_DOWN),
|
||||
RIGHT(CLUE_RIGHT),
|
||||
UP(CLUE_UP),
|
||||
LEFT(CLUE_LEFT);
|
||||
Clue(byte dir) {
|
||||
this.dir = dir;
|
||||
this.clueDir = dir;
|
||||
}
|
||||
final byte dir;
|
||||
final int clueDir;
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExportFormatFromFilled() {
|
||||
val clues = Clues.createEmpty();
|
||||
@@ -60,11 +38,11 @@ public class ExportFormatTest {
|
||||
clues.setClueLo(Idx.IDX_0_0.lo, RIGHT.dir);
|
||||
// This creates a slot starting at (0,1)
|
||||
// Terminate the slot at (0,5) with another digit to avoid it extending to MAX_WORD_LENGTH
|
||||
clues.setClueLo(Idx.IDX_0_5.lo, CLUE_LEFT);
|
||||
var grid = new Gridded(clues.toGrid());
|
||||
clues.setClueLo(Idx.IDX_0_5.lo, LEFT.dir);
|
||||
var grid = new Gridded(clues);
|
||||
|
||||
// key = (cellIndex << 2) | (direction)
|
||||
var key = Slot.packSlotKey(0, CLUE_RIGHT);
|
||||
var key = Slot.packSlotKey(0, RIGHT.dir);
|
||||
var lo = (1L << OFF_0_1) | (1L << OFF_0_2) | (1L << OFF_0_3) | (1L << OFF_0_4);
|
||||
|
||||
assertTrue(placeWord(grid.grid(), grid.grid().g, key, lo, 0L, TEST));
|
||||
@@ -112,7 +90,7 @@ public class ExportFormatTest {
|
||||
var grid = SwedishGeneratorTest.createEmpty();
|
||||
val clues = Clues.createEmpty();
|
||||
var fillResult = new FillResult(true, 0, 0, 0, 0, new FillStats());
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), new Gridded(grid), new Slotinfo[0], fillResult);
|
||||
var puzzleResult = new PuzzleResult(new Clued(clues), new Gridded(grid, clues), new Slotinfo[0], fillResult);
|
||||
|
||||
var exported = puzzleResult.exportFormatFromFilled(1, new Rewards(0, 0, 0));
|
||||
|
||||
@@ -133,13 +111,13 @@ public class ExportFormatTest {
|
||||
val words = entry.words();
|
||||
for (int i = 0; i < Math.min(words.length, 5); i++) {
|
||||
val wordVal = words[i];
|
||||
val word = Lemma.asWord(wordVal);
|
||||
val word = Lemma.asWord(wordVal, Export.BYTES.get());
|
||||
val assigned = new Assign(wordVal);
|
||||
val shard = Meta.shardKey(assigned.w);
|
||||
val clueRec = Meta.readRecord(shard, i);
|
||||
|
||||
assertNotNull(clueRec);
|
||||
assertEquals(word, Lemma.asWord(clueRec.w()));
|
||||
assertEquals(word, Lemma.asWord(clueRec.w(), Export.BYTES.get()));
|
||||
assertTrue(clueRec.simpel() >= 0);
|
||||
assertTrue(clueRec.clues().length > 0);
|
||||
}
|
||||
@@ -160,7 +138,7 @@ public class ExportFormatTest {
|
||||
int idx = -1;
|
||||
long[] words = entry.words();
|
||||
for (int i = 0; i < words.length; i++) {
|
||||
if (Lemma.asWord(words[i]).equals(wStr)) {
|
||||
if (Lemma.asWord(words[i], Export.BYTES.get()).equals(wStr)) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
@@ -170,7 +148,7 @@ public class ExportFormatTest {
|
||||
val shard = Meta.shardKey(w);
|
||||
val clueRec = Meta.readRecord(shard, idx);
|
||||
assertNotNull(clueRec);
|
||||
assertEquals(wStr, Lemma.asWord(clueRec.w()));
|
||||
assertEquals(wStr, Lemma.asWord(clueRec.w(), Export.BYTES.get()));
|
||||
// Check some expected complexity values (from CSV head output, column 3)
|
||||
if (wStr.equals("EEN")) {
|
||||
assertEquals(451, clueRec.simpel());
|
||||
|
||||
Reference in New Issue
Block a user