Migrate Lumen to Dart and Flutter 2.0
This commit is contained in:
Vendored
+242
@@ -0,0 +1,242 @@
|
||||
[
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "0",
|
||||
"solution": "1101101011000111101000000",
|
||||
"given": "1110101110011100111101111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "0",
|
||||
"solution": "1100000111001011111011000",
|
||||
"given": "1111101111011101111101011"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "0",
|
||||
"solution": "1111100100000101010001010",
|
||||
"given": "0000000000000101000000100"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "0",
|
||||
"solution": "0010010101110010010011101",
|
||||
"given": "0000100000110000010000000"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "1",
|
||||
"solution": "1000000111001011111001000",
|
||||
"given": "1101101100000111011100111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "1",
|
||||
"solution": "1000100111011001001110010",
|
||||
"given": "1101101001111101101111111"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "1",
|
||||
"solution": "0111001001011100100000011",
|
||||
"given": "0000101001011000100000000"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "1",
|
||||
"solution": "1000100111011001001110010",
|
||||
"given": "1000000000011001000000101"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "2",
|
||||
"solution": "1010011011100101101100111",
|
||||
"given": "1111111111001001101001101"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "2",
|
||||
"solution": "1000011100100011101010100",
|
||||
"given": "0100111001010111011001010"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "2",
|
||||
"solution": "1000011100100011101010100",
|
||||
"given": "0000000000000010001001000"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "2",
|
||||
"solution": "1000001110001001100111010",
|
||||
"given": "0001001100001000001000000"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "-1",
|
||||
"solution": "0001110010100001111110101",
|
||||
"given": "0101011010011111111111111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "-1",
|
||||
"solution": "1101110110010011010010101",
|
||||
"given": "0011000001010010001100110"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "-1",
|
||||
"solution": "1101110110010011010010101",
|
||||
"given": "0010000000010010000000010"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "-1",
|
||||
"solution": "1011110101110011110100001",
|
||||
"given": "0100000100000000000000000"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "1000001",
|
||||
"solution": "0101100010001001100010001",
|
||||
"given": "1101111100010100110111111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "1000001",
|
||||
"solution": "1100111110001000100110101",
|
||||
"given": "0110010101111100100110001"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "1000001",
|
||||
"solution": "1111011011111010101011011",
|
||||
"given": "0000000100000100000000001"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "1000001",
|
||||
"solution": "1011011100110000111000011",
|
||||
"given": "0010001100000101000000011"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "1000002",
|
||||
"solution": "0110111011010101110001010",
|
||||
"given": "1110100100001001101100000"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "1000002",
|
||||
"solution": "1010010100011110110100001",
|
||||
"given": "1111100001111110110111011"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "1000002",
|
||||
"solution": "0011111111000010110100111",
|
||||
"given": "0000000000000000001000000"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "1000002",
|
||||
"solution": "1100110110001001101011011",
|
||||
"given": "0100100100001000000000000"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "164371900",
|
||||
"solution": "0011001011111001000101001",
|
||||
"given": "1000011011011011111010111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "164371900",
|
||||
"solution": "1100110100011111010100100",
|
||||
"given": "1011111101010001101110001"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "164371900",
|
||||
"solution": "0010001010101001110011010",
|
||||
"given": "0010010000001000001000000"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "164371900",
|
||||
"solution": "0010111000011100110011101",
|
||||
"given": "0000100110000000000000010"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "180000000",
|
||||
"solution": "0100000100011011101111001",
|
||||
"given": "0111101011010001101111010"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "180000000",
|
||||
"solution": "1001100000101100010000001",
|
||||
"given": "0101101001011101010101001"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "180000000",
|
||||
"solution": "1111001100000110011001100",
|
||||
"given": "0000000000111000100000000"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "180000000",
|
||||
"solution": "0110110001001101001111110",
|
||||
"given": "0100000100000100010000001"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "9223372036854775807",
|
||||
"solution": "0001110010100001111110101",
|
||||
"given": "0101011010011111111111111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "9223372036854775807",
|
||||
"solution": "1101110110010011010010101",
|
||||
"given": "0011000001010010001100110"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "9223372036854775807",
|
||||
"solution": "1101110110010011010010101",
|
||||
"given": "0010000000010010000000010"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "9223372036854775807",
|
||||
"solution": "1011110101110011110100001",
|
||||
"given": "0100000100000000000000000"
|
||||
},
|
||||
{
|
||||
"kind": "legacy",
|
||||
"seed": "-9223372036854775808",
|
||||
"solution": "1101101011000111101000000",
|
||||
"given": "1110101110011100111101111"
|
||||
},
|
||||
{
|
||||
"kind": "EASY",
|
||||
"seed": "-9223372036854775808",
|
||||
"solution": "1100000111001011111011000",
|
||||
"given": "1111101111011101111101011"
|
||||
},
|
||||
{
|
||||
"kind": "MEDIUM",
|
||||
"seed": "-9223372036854775808",
|
||||
"solution": "1111100100000101010001010",
|
||||
"given": "0000000000000101000000100"
|
||||
},
|
||||
{
|
||||
"kind": "HARD",
|
||||
"seed": "-9223372036854775808",
|
||||
"solution": "0010010101110010010011101",
|
||||
"given": "0000100000110000010000000"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,163 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lumen/domain/puzzle.dart';
|
||||
import 'package:lumen/domain/book.dart';
|
||||
import 'package:lumen/domain/game.dart';
|
||||
import 'package:lumen/services/progress.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
test('Dart generation matches 40 Java reference boards including signed 64-bit seeds', () {
|
||||
final fixtures = jsonDecode(
|
||||
File('test/fixtures/java_boards.json').readAsStringSync(),
|
||||
) as List;
|
||||
for (final f in fixtures) {
|
||||
final seed = BigInt.parse(f['seed']),
|
||||
p = f['kind'] == 'legacy'
|
||||
? Puzzle.seeded(seed)
|
||||
: Puzzle.generate(seed, Difficulty.fromStored(f['kind']));
|
||||
expect(p.solution.join(), f['solution'], reason: '${f['kind']} $seed');
|
||||
expect(
|
||||
p.given.map((v) => v ? 1 : 0).join(),
|
||||
f['given'],
|
||||
reason: '${f['kind']} $seed givens',
|
||||
);
|
||||
}
|
||||
});
|
||||
test('300 generated practice boards have requested grades, unique answers and complete hints', () {
|
||||
for (final d in Difficulty.values) {
|
||||
for (var seed = 1000001; seed < 1000101; seed++) {
|
||||
final p = Puzzle.generate(BigInt.from(seed), d);
|
||||
expect(p.difficulty, d);
|
||||
expect(p.countSolutions(), 1);
|
||||
final solver = LogicSolver(25, p.constraints),
|
||||
analysis = solver.analyze(p.initial);
|
||||
expect(analysis.solved, true);
|
||||
expect(analysis.cells, p.solution);
|
||||
expect(p.solved(p.solution.map((v) => v == 1 ? 1 : 2).toList()), true);
|
||||
expect(p.solved(List.filled(25, 0)), false);
|
||||
}
|
||||
}
|
||||
});
|
||||
test(
|
||||
'area solver matches exhaustive enumeration for 300 random small systems',
|
||||
() {
|
||||
final rng = Random(42);
|
||||
for (var trial = 0; trial < 300; trial++) {
|
||||
final constraints = List.generate(1 + rng.nextInt(5), (k) {
|
||||
final cells = [
|
||||
for (var i = 0; i < 6; i++)
|
||||
if (rng.nextBool()) i,
|
||||
];
|
||||
return Constraint(cells, rng.nextInt(cells.length + 1), '$k');
|
||||
});
|
||||
var count = 0;
|
||||
for (var mask = 0; mask < 64; mask++) {
|
||||
if (constraints.every(
|
||||
(c) =>
|
||||
c.cells.fold<int>(0, (sum, i) => sum + ((mask >> i) & 1)) ==
|
||||
c.total,
|
||||
)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
expect(
|
||||
LogicSolver(6, constraints).countSolutions(List.filled(6, -1)),
|
||||
min(2, count),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
test('all campaign pictures unique; later entries require comparisons, without guessing', () async {
|
||||
final book = await Book.load();
|
||||
expect(book.levels.length, 12);
|
||||
for (var i = 0; i < 12; i++) {
|
||||
final p = book.levels[i].puzzle(),
|
||||
solver = LogicSolver(49, p.constraints);
|
||||
expect(p.countSolutions(), 1, reason: 'campaign $i');
|
||||
final a = solver.analyze(p.initial);
|
||||
expect(a.solved, true, reason: 'campaign $i');
|
||||
expect(a.cells, p.solution);
|
||||
if (i >= 2) {
|
||||
expect(solver.analyze(p.initial, useAreas: false).solved, false);
|
||||
expect(a.areaDeductions, greaterThan(0));
|
||||
}
|
||||
}
|
||||
});
|
||||
test('calendar streak handles repeats, missed days and DST boundaries', () {
|
||||
expect(completedStreak(100, 4, 100), 4);
|
||||
expect(completedStreak(100, 4, 101), 5);
|
||||
expect(completedStreak(100, 4, 102), 1);
|
||||
expect(visibleStreak(100, 4, 102), 0);
|
||||
expect(
|
||||
epochDay(DateTime(2026, 10, 26)) - epochDay(DateTime(2026, 10, 25)),
|
||||
1,
|
||||
);
|
||||
});
|
||||
test(
|
||||
'fresh Flutter progress ignores old saves; reading never awards completion',
|
||||
() async {
|
||||
final store = Progress.memory(), g = Game(await Book.load(), store);
|
||||
await g.restore();
|
||||
expect(g.screen, Screen.home);
|
||||
expect(g.solved, 0);
|
||||
expect(g.recoveredCount, 0);
|
||||
g.showStory(2);
|
||||
g.mark(0);
|
||||
final marks = List.of(g.cells);
|
||||
g.showStory(3);
|
||||
expect(g.solved, 0);
|
||||
expect(g.recovered(0), false);
|
||||
g.showStory(2);
|
||||
expect(g.cells, marks);
|
||||
g.undo();
|
||||
expect(g.cells[0], 0);
|
||||
final p = g.puzzle!;
|
||||
for (var i = 0; i < 49; i++) {
|
||||
while (g.cells[i] != (p.solution[i] == 1 ? 1 : 2)) {
|
||||
g.mark(i);
|
||||
}
|
||||
}
|
||||
expect(g.screen, Screen.story);
|
||||
expect(g.storyIndex, 3);
|
||||
expect(g.solved, 1);
|
||||
expect(g.recovered(0), true);
|
||||
g.showStory(2);
|
||||
g.check();
|
||||
expect(g.solved, 1);
|
||||
final restored = Game(g.book, Progress.memory(store.snapshot));
|
||||
await restored.restore();
|
||||
expect(restored.storyIndex, 2);
|
||||
expect(restored.solved, 1);
|
||||
},
|
||||
);
|
||||
test('daily completion awards once and practice difficulties keep separate levels', () async {
|
||||
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++) {
|
||||
while (g.cells[i] != (p.solution[i] == 1 ? 1 : 2)) {
|
||||
g.mark(i);
|
||||
}
|
||||
}
|
||||
expect(g.solved, 1);
|
||||
expect(g.progress.number('streak'), 1);
|
||||
g.check();
|
||||
expect(g.solved, 1);
|
||||
g.selectDifficulty(Difficulty.hard);
|
||||
await g.startPractice();
|
||||
expect(g.puzzle!.difficulty, Difficulty.hard);
|
||||
final hard = g.puzzle!;
|
||||
for (var i = 0; i < 25; i++) {
|
||||
while (g.cells[i] != (hard.solution[i] == 1 ? 1 : 2)) {
|
||||
g.mark(i);
|
||||
}
|
||||
}
|
||||
expect(g.practiceLevel, 2);
|
||||
g.selectDifficulty(Difficulty.easy);
|
||||
expect(g.practiceLevel, 1);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:lumen/domain/puzzle.dart';
|
||||
import 'package:lumen/ui/board.dart';
|
||||
import 'package:lumen/ui/paper.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('page margins turn leaves; grid drags never turn', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.reset();
|
||||
tester.view.physicalSize = const Size(600, 960);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
var turns = 0, marks = 0;
|
||||
final p = Puzzle(7, List.filled(49, 0));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Paper(
|
||||
onTurn: (d) => turns += d,
|
||||
child: Board(
|
||||
puzzle: p,
|
||||
cells: List.filled(49, 0),
|
||||
onMark: (_) => marks++,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.dragFrom(const Offset(585, 400), const Offset(-180, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(turns, 1);
|
||||
await tester.drag(
|
||||
find.byKey(const ValueKey('cell-20')),
|
||||
const Offset(70, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(turns, 1);
|
||||
await tester.tap(find.byKey(const ValueKey('cell-20')));
|
||||
expect(marks, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('paper supports small and landscape viewports and larger text', (
|
||||
tester,
|
||||
) async {
|
||||
addTearDown(tester.view.reset);
|
||||
for (final size in [const Size(360, 640), const Size(960, 600)]) {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(
|
||||
size: size,
|
||||
textScaler: const TextScaler.linear(1.5),
|
||||
),
|
||||
child: Scaffold(
|
||||
body: Leaf(
|
||||
body: Column(
|
||||
children: [
|
||||
writing('For you, when you are ready', size: 31),
|
||||
writing('A remembered passage. ' * 40),
|
||||
],
|
||||
),
|
||||
footer: InkButton('Next leaf', () {}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Next leaf'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user