Gather data

This commit is contained in:
mike
2026-01-06 02:57:17 +01:00
parent f031e97a58
commit effb1145d4
4 changed files with 89 additions and 51 deletions

View File

@@ -1,32 +1,68 @@
package puzzle;
//import org.junit.jupiter.api.Test;
//import static org.junit.jupiter.api.Assertions.*;
import puzzle.SwedishGenerator.Dict;
import puzzle.SwedishGenerator.Lemma;
import puzzle.SwedishGenerator.PuzzleResult;
import puzzle.SwedishGenerator.Rng;
import static puzzle.Main.indentLines;
public class MainTest {
static void main() {
new MainTest().testGeneratePuzzle();
public static void main(String[] args) {
new MainTest().testAttempt();
}
// @Test
public void testGeneratePuzzle() {
public void testAttempt() {
// Arrange
var opts = new Main.Opts();
opts.seed = 1234;
opts.pop = 18;
opts.gens = 300;
opts.wordsPath = "src/test/resources/puzzle/pool.txt";
//seed=1811328180
opts.seed = -1645461655;// (int) (System.nanoTime() ^ System.currentTimeMillis());
opts.pop = 18; // Small for micro-scale
opts.gens = 200;
opts.minSimplicity = 0;
opts.fillTimeout = 20_000;
opts.threads = 1;
opts.tries = 1;
opts.verbose = true;
opts.W = 3;
opts.H = 3;
// We need a small dictionary for testing
// Instead of loading from file, we might want a way to create a mock Dict
// But SwedishGenerator.loadWords(path) is what we have.
// Let's try to load a real one or a small subset if possible.
var dict = new Dict(new Lemma[]{
new Lemma(0, "NU", 1, 100, "NU"),
new Lemma(1, "ET", 2, 100, "ET"),
new Lemma(2, "NUT", 3, 1001, "NUT"),
new Lemma(3, "ETE", 4, 100, "ETE"),
new Lemma(4, "IK", 5, 100, "IK"),
new Lemma(5, "IN", 6, 100, "IN"),
new Lemma(6, "AU", 7, 100, "AU"),
new Lemma(7, "JE", 8, 100, "JE"),
new Lemma(8, "AI", 9, 100, "AI"),
new Lemma(9, "NA", 10, 100, "NA"),
new Lemma(10, "AF", 11, 100, "AF"),
new Lemma(11, "AL", 14, 1001, "AL"),
new Lemma(12, "EA", 15, 100, "EA"),
new Lemma(13, "AV", 18, 100, "AV"),
new Lemma(14, "IL", 19, 100, "IL"),
new Lemma(15, "EN", 22, 100, "EN")
});
// Act
var result = new Main().generatePuzzle(opts);
// Assert
/* assertNotNull(result);
assertNotNull(result.mask());
assertNotNull(result.filled());
assertTrue(result.filled().ok);*/
for (int i = 0; i < 200; i++) {
int seed = opts.seed + i;
var rng = new Rng(seed);
PuzzleResult res = Main.attempt(rng, dict, opts);
// Assert
if (res != null && res.filled().ok()) {
System.out.println("Test Passed: Puzzle generated");
System.out.println("Seed: " + seed);
System.out.print(indentLines(res.swe().renderHuman(res.filled().grid()), " "));
return;
}
}
System.out.println("Test Note: Puzzle not generated in 1 attempt (this is possible depending on RNG)");
}
}