Enhance postcard puzzles and narration
This commit is contained in:
@@ -114,6 +114,27 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('every Elias and echo cue uses the same cloned voice reference', () {
|
||||
final references = <String>{};
|
||||
var cloned = 0;
|
||||
for (final track in book.tracks.values) {
|
||||
for (final cue in track['cues'] as List) {
|
||||
final role = cue['speaker'];
|
||||
if (role == 'Elias' || role == 'The echo') {
|
||||
final synthesis = cue['synthesis'] as Map;
|
||||
expect(synthesis['engine'], 'qwen3-voice-clone');
|
||||
expect(synthesis['model'], 'Qwen/Qwen3-TTS-12Hz-1.7B-Base');
|
||||
references.add(synthesis['referenceSha256'] as String);
|
||||
cloned++;
|
||||
} else {
|
||||
expect(cue['synthesis'], isNull);
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(cloned, 93);
|
||||
expect(references.length, 1);
|
||||
});
|
||||
|
||||
test('all discoveries award once, survive read-ahead and restore independently of other books', () async {
|
||||
final store = Progress.memory();
|
||||
final g = Game(book, store, library: library);
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:lumen/domain/book.dart';
|
||||
import 'package:lumen/domain/game.dart';
|
||||
import 'package:lumen/main.dart';
|
||||
import 'package:lumen/services/narrator.dart';
|
||||
import 'package:lumen/services/browser_assets.dart';
|
||||
import 'package:lumen/services/progress.dart';
|
||||
|
||||
class _Voice extends Narrator {
|
||||
@@ -35,6 +36,18 @@ class _Voice extends Narrator {
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('web audio URLs distinguish updated recording content', () {
|
||||
final first = Uri.parse(
|
||||
browserAudioUrl('assets/audio/voice.wav', version: 'old-hash'),
|
||||
);
|
||||
final second = Uri.parse(
|
||||
browserAudioUrl('assets/audio/voice.wav', version: 'new-hash'),
|
||||
);
|
||||
expect(first.queryParameters['v'], 'old-hash');
|
||||
expect(second.queryParameters['v'], 'new-hash');
|
||||
expect(first.path, second.path);
|
||||
expect(first, isNot(second));
|
||||
});
|
||||
testWidgets('autoplay waits exactly three seconds and starts only once', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
+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 {
|
||||
|
||||
@@ -8,9 +8,11 @@ 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/main.dart';
|
||||
import 'package:lumen/services/ads.dart';
|
||||
import 'package:lumen/services/progress.dart';
|
||||
import 'package:lumen/ui/postcards.dart';
|
||||
|
||||
import 'postcards_test.dart' show solve;
|
||||
|
||||
@@ -51,6 +53,41 @@ void main() {
|
||||
'MaraHand',
|
||||
)..addFont(rootBundle.load('assets/fonts/DancingScript.ttf'))).load();
|
||||
});
|
||||
testWidgets('postcard reveal fades from a blurred memory to clear colour', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: PostcardRevealArt(card: islandPostcards.first)),
|
||||
);
|
||||
final blur = find.byType(ImageFiltered);
|
||||
final color = find.byKey(const ValueKey('postcard-reveal-color'));
|
||||
final initial = tester.widget<ColorFiltered>(color).colorFilter;
|
||||
expect(tester.widget<ImageFiltered>(blur).enabled, isTrue);
|
||||
await tester.pump(const Duration(milliseconds: 900));
|
||||
expect(tester.widget<ColorFiltered>(color).colorFilter, isNot(initial));
|
||||
expect(tester.widget<ImageFiltered>(blur).enabled, isTrue);
|
||||
await tester.pump(const Duration(milliseconds: 900));
|
||||
expect(tester.widget<ImageFiltered>(blur).enabled, isFalse);
|
||||
});
|
||||
testWidgets('later postcard puzzles show both lantern markers and the rule', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(600, 960);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final book = (await tester.runAsync(Book.load))!;
|
||||
final game = Game(book, Progress.memory())..startPostcard(2, 2);
|
||||
await tester.pumpWidget(LumenApp(game: game, adsEnabled: false));
|
||||
await tester.pumpAndSettle();
|
||||
final pair = game.puzzle!.lanternPairs.single;
|
||||
expect(find.byKey(ValueKey('lantern-${pair.first}')), findsOneWidget);
|
||||
expect(find.byKey(ValueKey('lantern-${pair.second}')), findsOneWidget);
|
||||
expect(
|
||||
find.text('Matching lanterns: exactly one of the two cells is lit.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets(
|
||||
'three patterns collect a readable postcard before a single no-fill break',
|
||||
(tester) async {
|
||||
@@ -76,10 +113,39 @@ void main() {
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.runAsync(() async {
|
||||
await precacheImage(
|
||||
const AssetImage('assets/postcards/illustrations/washing-line.png'),
|
||||
tester.element(find.byKey(const ValueKey('postcard-collection'))),
|
||||
);
|
||||
});
|
||||
await tester.pump();
|
||||
final lockedFilter = tester
|
||||
.widget<ColorFiltered>(find.byKey(const ValueKey('postcard-art-0')))
|
||||
.colorFilter;
|
||||
expect(
|
||||
tester
|
||||
.widget<ImageFiltered>(
|
||||
find.byKey(const ValueKey('postcard-blur-0')),
|
||||
)
|
||||
.enabled,
|
||||
isTrue,
|
||||
);
|
||||
await capture(tester, 'collection');
|
||||
await tester.tap(find.byKey(const ValueKey('start-postcard-0')));
|
||||
await tester.tap(find.byKey(const ValueKey('postcard-0')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(g.postcardSlot, 0);
|
||||
expect(find.byKey(const ValueKey('area-0')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('area-1')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('area-2')), findsOneWidget);
|
||||
await tester.ensureVisible(find.byKey(const ValueKey('area-1')));
|
||||
await tester.tap(find.byKey(const ValueKey('area-1')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(g.selectedArea, 1);
|
||||
expect(
|
||||
find.byKey(const ValueKey('selected-region-outline')),
|
||||
findsOneWidget,
|
||||
);
|
||||
await capture(tester, 'puzzle');
|
||||
for (var slot = 0; slot < 3; slot++) {
|
||||
solve(g);
|
||||
@@ -93,17 +159,66 @@ void main() {
|
||||
expect(ads.opportunities, 0);
|
||||
}
|
||||
expect(find.text('Keep this postcard'), findsOneWidget);
|
||||
final message = tester.widget<SelectableText>(
|
||||
find.byKey(const ValueKey('postcard-message')),
|
||||
);
|
||||
expect(message.style?.fontFamily, 'MaraHand');
|
||||
await capture(tester, 'collected');
|
||||
await tester.tap(find.text('Keep this postcard'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('postcard-reveal')), findsOneWidget);
|
||||
final revealedImage = tester.widget<Image>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('postcard-reveal')),
|
||||
matching: find.byType(Image),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
(revealedImage.image as AssetImage).assetName,
|
||||
'assets/postcards/illustrations/washing-line.png',
|
||||
);
|
||||
expect(ads.opportunities, 0);
|
||||
await capture(tester, 'reveal');
|
||||
await tester.tap(find.text('Back to collection'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(g.screen, Screen.postcards);
|
||||
expect(g.postcardsCollected, 1);
|
||||
expect(ads.opportunities, 1);
|
||||
await tester.ensureVisible(find.byKey(const ValueKey('read-postcard-0')));
|
||||
await tester.tap(find.byKey(const ValueKey('read-postcard-0')));
|
||||
expect(
|
||||
tester
|
||||
.widget<ImageFiltered>(
|
||||
find.byKey(const ValueKey('postcard-blur-0')),
|
||||
)
|
||||
.enabled,
|
||||
isFalse,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<ImageFiltered>(
|
||||
find.byKey(const ValueKey('postcard-blur-1')),
|
||||
)
|
||||
.enabled,
|
||||
isTrue,
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<ColorFiltered>(find.byKey(const ValueKey('postcard-art-0')))
|
||||
.colorFilter,
|
||||
isNot(lockedFilter),
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<ColorFiltered>(find.byKey(const ValueKey('postcard-art-1')))
|
||||
.colorFilter,
|
||||
lockedFilter,
|
||||
);
|
||||
await tester.ensureVisible(find.byKey(const ValueKey('postcard-0')));
|
||||
await tester.tap(find.byKey(const ValueKey('postcard-0')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Keep this postcard'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Back to collection'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(ads.opportunities, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
@@ -127,7 +242,7 @@ void main() {
|
||||
g.startPostcard(0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
for (var i = 0; i < 25; i++) {
|
||||
for (var i = 0; i < 49; i++) {
|
||||
final bounds = tester.getRect(find.byKey(ValueKey('cell-$i')));
|
||||
expect(bounds.top, greaterThanOrEqualTo(0));
|
||||
expect(bounds.bottom, lessThanOrEqualTo(size.height));
|
||||
@@ -144,6 +259,10 @@ void main() {
|
||||
expect(find.text('Keep this postcard').hitTestable(), findsOneWidget);
|
||||
await tester.tap(find.text('Keep this postcard'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('postcard-reveal')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.tap(find.text('Back to collection'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
}
|
||||
},
|
||||
|
||||
+18
-2
@@ -195,6 +195,20 @@ void main() {
|
||||
}
|
||||
}
|
||||
});
|
||||
test('new 7x7 generated boards retain their grade, uniqueness and deterministic clues', () {
|
||||
for (final d in Difficulty.values) {
|
||||
for (var seed = 1000001; seed < 1000031; seed++) {
|
||||
final p = Puzzle.generateSeven(BigInt.from(seed), d);
|
||||
final repeat = Puzzle.generateSeven(BigInt.from(seed), d);
|
||||
expect(p.size, 7);
|
||||
expect(p.difficulty, d);
|
||||
expect(p.countSolutions(), 1);
|
||||
expect(LogicSolver(49, p.constraints).analyze(p.initial).solved, true);
|
||||
expect(p.solution, repeat.solution);
|
||||
expect(p.given, repeat.given);
|
||||
}
|
||||
}
|
||||
});
|
||||
test(
|
||||
'area solver matches exhaustive enumeration for 300 random small systems',
|
||||
() {
|
||||
@@ -350,7 +364,8 @@ void main() {
|
||||
final store = Progress.memory(), g = Game(await Book.load(), store);
|
||||
g.startDaily(DateTime(2026, 10, 31));
|
||||
final p = g.puzzle!;
|
||||
for (var i = 0; i < 25; i++) {
|
||||
expect(p.size, 7);
|
||||
for (var i = 0; i < p.solution.length; i++) {
|
||||
while (g.cells[i] != (p.solution[i] == 1 ? 1 : 2)) {
|
||||
g.mark(i);
|
||||
}
|
||||
@@ -363,7 +378,8 @@ void main() {
|
||||
await g.startPractice();
|
||||
expect(g.puzzle!.difficulty, Difficulty.hard);
|
||||
final hard = g.puzzle!;
|
||||
for (var i = 0; i < 25; i++) {
|
||||
expect(hard.size, 7);
|
||||
for (var i = 0; i < hard.solution.length; i++) {
|
||||
while (g.cells[i] != (hard.solution[i] == 1 ? 1 : 2)) {
|
||||
g.mark(i);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user