cyberhybridhub/server/test/spelling/spelling_item_selector_test.dart
nathanAndrinoid 4459852f83
Some checks failed
Admin portal tests / test (push) Has been cancelled
spelling
2026-06-05 03:22:35 +00:00

83 lines
2.4 KiB
Dart

import 'dart:math';
import 'package:cyberhybridhub_server/spelling/spelling_item_record.dart';
import 'package:cyberhybridhub_server/spelling/spelling_item_selector.dart';
import 'package:cyberhybridhub_server/spelling/spelling_progress_policy.dart';
import 'package:test/test.dart';
void main() {
test('mastered item is still selectable over many draws', () {
final SpellingItemSelector selector = SpellingItemSelector(random: Random(99));
const SpellingItemRecord mastered = SpellingItemRecord(
id: 'mastered',
spellingWordId: 'w1',
canonicalWord: 'separate',
displayedWord: 'separate',
isCorrectlySpelled: true,
correctAnswer: 10,
familiarityScore: 20,
);
const SpellingItemRecord fresh = SpellingItemRecord(
id: 'fresh',
spellingWordId: 'w2',
canonicalWord: 'rhythm',
displayedWord: 'rythm',
isCorrectlySpelled: false,
correctAnswer: -10,
familiarityScore: 0,
);
var masteredHits = 0;
for (var i = 0; i < 500; i++) {
final SpellingItemRecord? pick = selector.pickFromCandidates(
<SpellingItemRecord>[mastered, fresh],
);
if (pick!.id == mastered.id) {
masteredHits++;
}
}
expect(masteredHits, greaterThan(0));
expect(
SpellingProgressPolicy.weightForScore(mastered.familiarityScore),
SpellingProgressPolicy.minWeight,
);
});
test('struggling item is picked more often than mastered peer', () {
final SpellingItemSelector selector = SpellingItemSelector(random: Random(7));
const SpellingItemRecord struggling = SpellingItemRecord(
id: 'struggling',
spellingWordId: 'w1',
canonicalWord: 'separate',
displayedWord: 'seperate',
isCorrectlySpelled: false,
correctAnswer: -10,
familiarityScore: -4,
);
const SpellingItemRecord mastered = SpellingItemRecord(
id: 'mastered',
spellingWordId: 'w2',
canonicalWord: 'rhythm',
displayedWord: 'rhythm',
isCorrectlySpelled: true,
correctAnswer: 10,
familiarityScore: 8,
);
var strugglingHits = 0;
for (var i = 0; i < 300; i++) {
final SpellingItemRecord? pick = selector.pickFromCandidates(
<SpellingItemRecord>[struggling, mastered],
);
if (pick!.id == struggling.id) {
strugglingHits++;
}
}
expect(strugglingHits, greaterThan(150));
});
}