Files
puzzle-generator/src/test/java/puzzle/MainTest.java
2026-01-06 02:57:17 +01:00

69 lines
2.5 KiB
Java

package puzzle;
import puzzle.SwedishGenerator.Dict;
import puzzle.SwedishGenerator.Lemma;
import puzzle.SwedishGenerator.PuzzleResult;
import puzzle.SwedishGenerator.Rng;
import static puzzle.Main.indentLines;
public class MainTest {
public static void main(String[] args) {
new MainTest().testAttempt();
}
public void testAttempt() {
// Arrange
var opts = new Main.Opts();
//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
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)");
}
}