You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.8 KiB
102 lines
2.8 KiB
import 'package:test/test.dart';
|
|
import 'package:practice_engine/models/question.dart';
|
|
import 'package:practice_engine/algorithms/spaced_repetition.dart';
|
|
|
|
void main() {
|
|
group('SpacedRepetition', () {
|
|
test('baseKnownProbability for never-seen known question', () {
|
|
final weight = SpacedRepetition.calculateKnownQuestionWeight(
|
|
lastAttemptIndex: -1,
|
|
currentAttemptIndex: 0,
|
|
);
|
|
|
|
expect(weight, equals(SpacedRepetition.baseKnownProbability));
|
|
});
|
|
|
|
test('probability increases with attempts since last seen', () {
|
|
final weight1 = SpacedRepetition.calculateKnownQuestionWeight(
|
|
lastAttemptIndex: 0,
|
|
currentAttemptIndex: 10,
|
|
);
|
|
|
|
final weight2 = SpacedRepetition.calculateKnownQuestionWeight(
|
|
lastAttemptIndex: 0,
|
|
currentAttemptIndex: 30,
|
|
);
|
|
|
|
expect(weight2, greaterThan(weight1));
|
|
});
|
|
|
|
test('probability is capped at maxKnownProbability', () {
|
|
final weight = SpacedRepetition.calculateKnownQuestionWeight(
|
|
lastAttemptIndex: 0,
|
|
currentAttemptIndex: 1000,
|
|
);
|
|
|
|
expect(weight, lessThanOrEqualTo(SpacedRepetition.maxKnownProbability));
|
|
});
|
|
|
|
test('probability increases gradually', () {
|
|
final weights = <double>[];
|
|
for (int i = 0; i <= 30; i++) {
|
|
final weight = SpacedRepetition.calculateKnownQuestionWeight(
|
|
lastAttemptIndex: 0,
|
|
currentAttemptIndex: i,
|
|
);
|
|
weights.add(weight);
|
|
}
|
|
|
|
// Should be monotonically increasing
|
|
for (int i = 1; i < weights.length; i++) {
|
|
expect(weights[i], greaterThanOrEqualTo(weights[i - 1]));
|
|
}
|
|
});
|
|
|
|
test('getQuestionWeight uses priority for unknown questions', () {
|
|
final question = Question(
|
|
id: 'q1',
|
|
prompt: 'Test',
|
|
answers: ['A', 'B'],
|
|
correctAnswerIndices: [0],
|
|
isKnown: false,
|
|
priorityPoints: 10,
|
|
);
|
|
|
|
final weight = SpacedRepetition.getQuestionWeight(
|
|
question: question,
|
|
currentAttemptIndex: 0,
|
|
basePriorityWeight: 1.0,
|
|
);
|
|
|
|
// Should be priority + 1
|
|
expect(weight, equals(11.0));
|
|
});
|
|
|
|
test('getQuestionWeight uses spaced repetition for known questions', () {
|
|
final question = Question(
|
|
id: 'q1',
|
|
prompt: 'Test',
|
|
answers: ['A', 'B'],
|
|
correctAnswerIndices: [0],
|
|
isKnown: true,
|
|
lastAttemptIndex: 5,
|
|
priorityPoints: 0,
|
|
);
|
|
|
|
final weight = SpacedRepetition.getQuestionWeight(
|
|
question: question,
|
|
currentAttemptIndex: 10,
|
|
basePriorityWeight: 1.0,
|
|
);
|
|
|
|
// Should use spaced repetition probability
|
|
final expected = SpacedRepetition.calculateKnownQuestionWeight(
|
|
lastAttemptIndex: 5,
|
|
currentAttemptIndex: 10,
|
|
);
|
|
expect(weight, closeTo(expected, 0.001));
|
|
});
|
|
});
|
|
}
|
|
|