Initial commit: CookIT recipe collection and week planner
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
7d7a0bc60b
173 files changed
+22803
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:cookit/src/planning/week_fill.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../support/fixtures.dart';
|
||||
|
||||
void main() {
|
||||
final days = [for (var d = 19; d <= 25; d++) DateTime.utc(2026, 10, d)];
|
||||
final recipes = [for (var i = 0; i < 5; i++) recipe(id: 'r$i', name: 'R$i')];
|
||||
|
||||
test('fills each empty day with a different Recipe, never one already in the week', () {
|
||||
final filled = fillWeek(
|
||||
emptyDays: days.take(3).toList(),
|
||||
candidates: recipes,
|
||||
inWeek: {'r0'},
|
||||
recent: const {},
|
||||
random: Random(1),
|
||||
);
|
||||
expect(filled.keys, days.take(3));
|
||||
final ids = filled.values.map((r) => r.id).toList();
|
||||
expect(ids.toSet(), hasLength(3));
|
||||
expect(ids, isNot(contains('r0')));
|
||||
});
|
||||
|
||||
test('recently planned Recipes come only after the others', () {
|
||||
for (var seed = 0; seed < 20; seed++) {
|
||||
final filled = fillWeek(
|
||||
emptyDays: days.take(4).toList(),
|
||||
candidates: recipes,
|
||||
inWeek: const {},
|
||||
recent: {'r0', 'r1'},
|
||||
random: Random(seed),
|
||||
);
|
||||
final ids = filled.values.map((r) => r.id).toList();
|
||||
expect(ids.take(3).toSet(), {'r2', 'r3', 'r4'});
|
||||
expect(ids.last, anyOf('r0', 'r1'));
|
||||
}
|
||||
});
|
||||
|
||||
test('days stay empty when the Recipes run out', () {
|
||||
final filled = fillWeek(
|
||||
emptyDays: days,
|
||||
candidates: recipes.take(2).toList(),
|
||||
inWeek: const {},
|
||||
recent: const {},
|
||||
random: Random(2),
|
||||
);
|
||||
expect(filled, hasLength(2));
|
||||
});
|
||||
|
||||
test('pickReplacement skips the week and returns null when nothing is left', () {
|
||||
final pick = pickReplacement(
|
||||
candidates: recipes,
|
||||
inWeek: {'r0', 'r1', 'r2', 'r3'},
|
||||
recent: const {},
|
||||
random: Random(),
|
||||
);
|
||||
expect(pick?.id, 'r4');
|
||||
expect(
|
||||
pickReplacement(candidates: recipes, inWeek: {for (final r in recipes) r.id}, recent: const {}, random: Random()),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user