introduce bitloops
This commit is contained in:
@@ -360,4 +360,78 @@ public class SwedishGeneratorTest {
|
||||
assertEquals(DASH, grid.byteAt(Grid.offset(0, 1)));
|
||||
assertEquals(DASH, grid.byteAt(Grid.offset(0, 2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInnerWorkings() {
|
||||
// 1. Test Slot.increasing
|
||||
assertFalse(Slot.increasing(1)); // Left
|
||||
assertTrue(Slot.increasing(2)); // Right
|
||||
assertTrue(Slot.increasing(3)); // Down
|
||||
assertFalse(Slot.increasing(4)); // Up
|
||||
|
||||
var sInc = Slot.from((0 << Slot.BIT_FOR_DIR) | 2, 1L, 0L);
|
||||
assertTrue(sInc.increasing());
|
||||
var sDec = Slot.from((0 << Slot.BIT_FOR_DIR) | 1, 1L, 0L);
|
||||
assertFalse(sDec.increasing());
|
||||
|
||||
// 2. Test slotScore
|
||||
int[] counts = new int[SIZE];
|
||||
counts[1] = 2;
|
||||
counts[2] = 3;
|
||||
var sScore = Slot.from(0, (1L << 1) | (1L << 2), 0L);
|
||||
// cross = (counts[1]-1) + (counts[2]-1) = 1 + 2 = 3
|
||||
// score = 3 * 10 + len(2) = 32
|
||||
assertEquals(32, slotScore(counts, sScore));
|
||||
|
||||
// 3. Test candidateCountForPattern
|
||||
var words = new long[] {
|
||||
Lemma.from("AT"),
|
||||
Lemma.from("CAT"),
|
||||
Lemma.from("DOGS"),
|
||||
Lemma.from("APPLE"),
|
||||
Lemma.from("APPLY"),
|
||||
Lemma.from("BANAN"),
|
||||
Lemma.from("BANANA"),
|
||||
Lemma.from("BANANAS"),
|
||||
Lemma.from("BANANASS") // length 8
|
||||
};
|
||||
|
||||
var dict = new Dict(words);
|
||||
var entry5 = dict.index()[5];
|
||||
|
||||
var ctx = new Context();
|
||||
ctx.setPattern(Lemma.pack("APP".getBytes(StandardCharsets.US_ASCII)));
|
||||
assertEquals(2, candidateCountForPattern(ctx, entry5));
|
||||
|
||||
ctx.setPattern(Lemma.pack("BAN".getBytes(StandardCharsets.US_ASCII)));
|
||||
assertEquals(1, candidateCountForPattern(ctx, entry5));
|
||||
|
||||
ctx.setPattern(Lemma.pack("CAT".getBytes(StandardCharsets.US_ASCII)));
|
||||
assertEquals(0, candidateCountForPattern(ctx, entry5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMaskFitnessDetailed() {
|
||||
var gen = new SwedishGenerator(new Rng(42));
|
||||
var grid = Grid.createEmpty();
|
||||
|
||||
// Empty grid: huge penalty
|
||||
long fitEmpty = gen.maskFitness(grid);
|
||||
assertTrue(fitEmpty >= 1_000_000_000L);
|
||||
|
||||
// Grid with one short slot: still high penalty but less than empty
|
||||
grid.setClue(0, D_BYTE_2); // Right from 0,0. Len 2 if 3x3.
|
||||
long fitOne = gen.maskFitness(grid);
|
||||
assertTrue(fitOne < fitEmpty);
|
||||
|
||||
// Test penalty for TARGET_CLUES
|
||||
// TARGET_CLUES = SIZE >>> 2. For 3x3 it is 9 >>> 2 = 2.
|
||||
// If we have 1 clue, |1 - 2| * 16000 = 16000 penalty.
|
||||
// If we add another clue at a distant position.
|
||||
var grid2 = Grid.createEmpty();
|
||||
grid2.setClue(0, D_BYTE_2);
|
||||
grid2.setClue(Grid.offset(2, 0), D_BYTE_2);
|
||||
// Now clueCount = 2, penalty should be 0 from target clues.
|
||||
// But they might have other penalties (short slots, etc.)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user