introduce bitloops
This commit is contained in:
@@ -35,10 +35,10 @@ public class ExportFormatTest {
|
||||
clueMap.put(key, lemma.word());
|
||||
|
||||
// Manually fill the grid letters for "TEST" at (0,1), (0,2), (0,3), (0,4)
|
||||
grid.setByteAt(Grid.offset(0, 1), (byte) 'T');
|
||||
grid.setByteAt(Grid.offset(0, 2), (byte) 'E');
|
||||
grid.setByteAt(Grid.offset(0, 3), (byte) 'S');
|
||||
grid.setByteAt(Grid.offset(0, 4), (byte) 'T');
|
||||
grid.setLetter(Grid.offset(0, 1), (byte) 'T');
|
||||
grid.setLetter(Grid.offset(0, 2), (byte) 'E');
|
||||
grid.setLetter(Grid.offset(0, 3), (byte) 'S');
|
||||
grid.setLetter(Grid.offset(0, 4), (byte) 'T');
|
||||
// Terminate thGrid.offset(e slot at) (0,5) with another digit to avoid it extending to MAX_WORD_LENGTH
|
||||
grid.setClue(Grid.offset(0, 5), (byte) '1');
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ public class MainTest {
|
||||
// Set up digits on the grid to create slots.
|
||||
// '2' (right) at (0,0) -> slot at (0,1), (0,2)
|
||||
grid.setClue(0, (byte) '2');
|
||||
grid.setByteAt(Grid.offset(0, 1), (byte) 'A');
|
||||
grid.setByteAt(Grid.offset(0, 2), (byte) 'B');
|
||||
grid.setLetter(Grid.offset(0, 1), (byte) 'A');
|
||||
grid.setLetter(Grid.offset(0, 2), (byte) 'B');
|
||||
|
||||
var slots = extractSlots(grid);
|
||||
assertEquals(1, slots.size());
|
||||
@@ -77,9 +77,9 @@ public class MainTest {
|
||||
var grid = Grid.createEmpty();
|
||||
|
||||
// Test set/get
|
||||
grid.setByteAt(Grid.offset(0, 0), (byte) 'A');
|
||||
grid.setLetter(Grid.offset(0, 0), (byte) 'A');
|
||||
grid.setClue(Grid.offset(1, 2), (byte) '5');
|
||||
grid.setByteAt(Grid.offset(2, 3), (byte) 'Z');
|
||||
grid.setLetter(Grid.offset(2, 3), (byte) 'Z');
|
||||
|
||||
Assertions.assertEquals((byte) 'A', grid.byteAt(Grid.offset(0, 0)));
|
||||
Assertions.assertEquals((byte) '5', grid.byteAt(Grid.offset(1, 2)));
|
||||
@@ -93,30 +93,30 @@ public class MainTest {
|
||||
Assertions.assertFalse(grid.isLetterSet(Grid.offset(1, 1)));
|
||||
|
||||
// Test isDigitAt
|
||||
Assertions.assertFalse(grid.isDigitAt(0));
|
||||
Assertions.assertTrue(grid.isDigitAt(Grid.offset(1, 2)));
|
||||
Assertions.assertFalse(grid.isClue(0));
|
||||
Assertions.assertTrue(grid.isClue(Grid.offset(1, 2)));
|
||||
Assertions.assertEquals(5, grid.digitAt(Grid.offset(1, 2)));
|
||||
Assertions.assertFalse(grid.isDigitAt(Grid.offset(2, 3)));
|
||||
Assertions.assertFalse(grid.isDigitAt(Grid.offset(1, 1)));
|
||||
Assertions.assertFalse(grid.isClue(Grid.offset(2, 3)));
|
||||
Assertions.assertFalse(grid.isClue(Grid.offset(1, 1)));
|
||||
|
||||
// Test isLettercell
|
||||
Assertions.assertTrue(grid.isLetterAt(Grid.offset(0, 0))); // 'A' is letter
|
||||
Assertions.assertFalse(grid.isLetterAt(Grid.offset(1, 2))); // '5' is digit
|
||||
Assertions.assertTrue(grid.isLetterAt(Grid.offset(1, 1))); // '#' is lettercell
|
||||
Assertions.assertTrue(grid.notClue(Grid.offset(0, 0))); // 'A' is letter
|
||||
Assertions.assertTrue(grid.isClue(Grid.offset(1, 2))); // '5' is digit
|
||||
Assertions.assertTrue(grid.notClue(Grid.offset(1, 1))); // '#' is lettercell
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGridDeepCopy() {
|
||||
var grid = Grid.createEmpty();
|
||||
grid.setByteAt(Grid.offset(0, 0), (byte) 'A');
|
||||
grid.setByteAt(Grid.offset(0, 1), (byte) 'B');
|
||||
grid.setByteAt(Grid.offset(1, 0), (byte) 'C');
|
||||
grid.setByteAt(Grid.offset(1, 1), (byte) 'D');
|
||||
grid.setLetter(Grid.offset(0, 0), (byte) 'A');
|
||||
grid.setLetter(Grid.offset(0, 1), (byte) 'B');
|
||||
grid.setLetter(Grid.offset(1, 0), (byte) 'C');
|
||||
grid.setLetter(Grid.offset(1, 1), (byte) 'D');
|
||||
|
||||
var copy = grid.deepCopyGrid();
|
||||
Assertions.assertEquals((byte) 'A', copy.byteAt(0));
|
||||
|
||||
copy.setByteAt(0, (byte) 'X');
|
||||
copy.setLetter(0, (byte) 'X');
|
||||
Assertions.assertEquals((byte) 'X', copy.byteAt(0));
|
||||
Assertions.assertEquals((byte) 'A', grid.byteAt(0)); // Original should be unchanged
|
||||
}
|
||||
@@ -126,7 +126,7 @@ public class MainTest {
|
||||
var grid = Grid.createEmpty();
|
||||
val idx = Grid.offset(1, 1);
|
||||
grid.setClue(idx, (byte) '1');
|
||||
Assertions.assertTrue(grid.isDigitAt(idx));
|
||||
Assertions.assertTrue(grid.isClue(idx));
|
||||
}
|
||||
@Test
|
||||
public void testAttempt() {
|
||||
|
||||
@@ -68,21 +68,21 @@ public class SwedishGeneratorTest {
|
||||
@Test
|
||||
void testGrid() {
|
||||
var grid = Grid.createEmpty();
|
||||
grid.setByteAt(0, (byte) 'A');
|
||||
grid.setLetter(0, (byte) 'A');
|
||||
grid.setClue(Grid.offset(0, 1), (byte) '1');
|
||||
|
||||
assertEquals('A', grid.byteAt(0));
|
||||
assertEquals(1, grid.digitAt(Grid.offset(0, 1)));
|
||||
assertTrue(grid.isLetterAt(0));
|
||||
assertFalse(grid.isDigitAt(0));
|
||||
assertTrue(grid.isDigitAt(Grid.offset(0, 1)));
|
||||
assertFalse(grid.isClue(0));
|
||||
assertTrue(grid.isClue(Grid.offset(0, 1)));
|
||||
assertFalse(grid.isLetterAt(Grid.offset(0, 1)));
|
||||
assertTrue(grid.isLetterAt(0));
|
||||
assertFalse(grid.isLetterAt(Grid.offset(0, 1)));
|
||||
|
||||
var copy = grid.deepCopyGrid();
|
||||
assertEquals('A', copy.byteAt(0));
|
||||
copy.setByteAt(0, (byte) 'B');
|
||||
copy.setLetter(0, (byte) 'B');
|
||||
assertEquals('B', copy.byteAt(0));
|
||||
assertEquals('A', grid.byteAt(0));
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public class SwedishGeneratorTest {
|
||||
|
||||
// 4. Partial placement then conflict (rollback)
|
||||
grid = Grid.createEmpty();
|
||||
grid.setByteAt(Grid.offset(0, 2), (byte) 'X'); // Conflict at the end
|
||||
grid.setLetter(Grid.offset(0, 2), (byte) 'X'); // Conflict at the end
|
||||
assertFalse(placeWord(grid, s, w1, undoBuffer, 3));
|
||||
// Verify grid is still empty (except for 'X')
|
||||
assertEquals(DASH, grid.byteAt(Grid.offset(0, 0)));
|
||||
|
||||
Reference in New Issue
Block a user