Enhance postcard puzzles and narration
This commit is contained in:
+102
-1
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lumen/domain/book.dart';
|
||||
import 'package:lumen/domain/game.dart';
|
||||
import 'package:lumen/domain/library.dart';
|
||||
import 'package:lumen/domain/postcards.dart';
|
||||
import 'package:lumen/domain/puzzle.dart';
|
||||
import 'package:lumen/services/ad_pacing.dart';
|
||||
@@ -20,6 +21,51 @@ void solve(Game game) {
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test('hidden totals and mirrored pairs agree with the saved solutions', () {
|
||||
var hidden = 0, mirrors = 0, trails = 0;
|
||||
for (final card in islandPostcards) {
|
||||
for (var slot = 0; slot < 3; slot++) {
|
||||
final p = card.puzzle(slot);
|
||||
for (final trail in p.footprintTrails) {
|
||||
trails++;
|
||||
expect(trail.length, 3);
|
||||
expect(p.solution[trail[1]], 1);
|
||||
expect(p.solution[trail[0]] + p.solution[trail[2]], 1);
|
||||
}
|
||||
final row = p.hiddenRow;
|
||||
if (row != null) {
|
||||
hidden++;
|
||||
expect(p.rows[row], p.rows[row - 1] + 1);
|
||||
}
|
||||
for (final pair in p.mirrorPairs) {
|
||||
mirrors++;
|
||||
expect(p.solution[pair.first], p.solution[pair.second]);
|
||||
final c = p.constraints.firstWhere((c) => c.equal);
|
||||
final solver = LogicSolver(49, [c]);
|
||||
for (final value in [0, 1]) {
|
||||
final known = List<int>.filled(49, -1)..[pair.first] = value;
|
||||
expect(solver.nextHint(known)!.value, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(hidden, greaterThan(0));
|
||||
expect(mirrors, greaterThan(0));
|
||||
expect(trails, greaterThan(0));
|
||||
});
|
||||
test('every bundled story puzzle is at least seven by seven', () async {
|
||||
final library = await StoryLibrary.load();
|
||||
for (final definition in library.stories) {
|
||||
final book = await library.open(definition.id);
|
||||
for (final level in book.levels) {
|
||||
expect(
|
||||
level.puzzle().size,
|
||||
greaterThanOrEqualTo(7),
|
||||
reason: '${definition.id}: ${level.id}',
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
test(
|
||||
'all 42 frozen boards are distinct, unique and solvable without guessing',
|
||||
() {
|
||||
@@ -27,11 +73,26 @@ void main() {
|
||||
for (final card in islandPostcards) {
|
||||
for (var slot = 0; slot < 3; slot++) {
|
||||
final p = card.puzzle(slot);
|
||||
expect(p.regions.map((r) => r.label), ['A', 'B', 'C']);
|
||||
expect(
|
||||
p.regions.every(
|
||||
(r) =>
|
||||
r.top >= 0 &&
|
||||
r.left >= 0 &&
|
||||
r.top + r.height <= p.size &&
|
||||
r.left + r.width <= p.size,
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
p.constraints.where((c) => c.name.startsWith('Area ')).length,
|
||||
3,
|
||||
);
|
||||
expect(pictures.add(p.solution.join()), isTrue);
|
||||
expect(keys.add(card.puzzleKey(slot)), isTrue);
|
||||
expect(p.countSolutions(), 1);
|
||||
expect(
|
||||
LogicSolver(25, p.constraints).analyze(p.initial).solved,
|
||||
LogicSolver(49, p.constraints).analyze(p.initial).solved,
|
||||
isTrue,
|
||||
);
|
||||
}
|
||||
@@ -40,6 +101,31 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test('later postcard lanterns link two editable opposite cells and give correct hints', () {
|
||||
for (var index = 0; index < islandPostcards.length; index++) {
|
||||
for (var slot = 0; slot < 3; slot++) {
|
||||
final puzzle = islandPostcards[index].puzzle(slot);
|
||||
expect(puzzle.lanternPairs.length, index >= 2 && slot == 2 ? 1 : 0);
|
||||
for (final pair in puzzle.lanternPairs) {
|
||||
expect(puzzle.given[pair.first], isFalse);
|
||||
expect(puzzle.given[pair.second], isFalse);
|
||||
expect(puzzle.solution[pair.first] + puzzle.solution[pair.second], 1);
|
||||
final constraint = puzzle.constraints.firstWhere(
|
||||
(c) => c.name == 'Lantern pair',
|
||||
);
|
||||
final solver = LogicSolver(49, [constraint]);
|
||||
for (final first in [0, 1]) {
|
||||
final known = List<int>.filled(49, -1)..[pair.first] = first;
|
||||
final hint = solver.nextHint(known)!;
|
||||
expect(hint.cell, pair.second);
|
||||
expect(hint.value, 1 - first);
|
||||
expect(hint.explanation, contains('lantern'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('postcards resume marks across books and never overwrite a reading position', () async {
|
||||
final book = await Book.load();
|
||||
final store = Progress.memory();
|
||||
@@ -82,6 +168,21 @@ void main() {
|
||||
expect(reloaded.storyIndex, 2);
|
||||
});
|
||||
|
||||
test('legacy completions survive the 7x7 upgrade', () async {
|
||||
final card = islandPostcards.first;
|
||||
final store = Progress.memory({
|
||||
for (var i = 0; i < 3; i++) 'done_${card.legacyPuzzleKey(i)}': true,
|
||||
'grid_${islandPostcards[1].legacyPuzzleKey(0)}': '1' * 25,
|
||||
});
|
||||
final g = Game(await Book.load(), store);
|
||||
expect(g.postcardsCollected, 1);
|
||||
g.startPostcard(1);
|
||||
expect(g.puzzle!.size, 7);
|
||||
expect(g.cells.length, 49);
|
||||
expect(g.key, islandPostcards[1].puzzleKey(0));
|
||||
expect(g.cells.where((cell) => cell == 0), isNotEmpty);
|
||||
});
|
||||
|
||||
test(
|
||||
'a practice milestone can offer only one break across restarts',
|
||||
() async {
|
||||
|
||||
Reference in New Issue
Block a user