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( [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( [struggling, mastered], ); if (pick!.id == struggling.id) { strugglingHits++; } } expect(strugglingHits, greaterThan(150)); }); }