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.
126 lines
3.8 KiB
126 lines
3.8 KiB
import 'package:test/test.dart';
|
|
import 'package:practice_engine/models/deck.dart';
|
|
import 'package:practice_engine/models/deck_config.dart';
|
|
import 'package:practice_engine/models/question.dart';
|
|
import 'package:practice_engine/logic/deck_service.dart';
|
|
|
|
void main() {
|
|
group('Manual Override Logic', () {
|
|
late DeckConfig config;
|
|
late Deck deck;
|
|
|
|
setUp(() {
|
|
config = const DeckConfig(requiredConsecutiveCorrect: 3);
|
|
deck = Deck(
|
|
id: 'deck1',
|
|
title: 'Test Deck',
|
|
description: 'Test',
|
|
questions: [
|
|
Question(
|
|
id: 'q1',
|
|
prompt: 'Question 1',
|
|
answers: ['A', 'B'],
|
|
correctAnswerIndices: [0],
|
|
consecutiveCorrect: 1,
|
|
isKnown: false,
|
|
priorityPoints: 5,
|
|
),
|
|
Question(
|
|
id: 'q2',
|
|
prompt: 'Question 2',
|
|
answers: ['A', 'B'],
|
|
correctAnswerIndices: [0],
|
|
consecutiveCorrect: 0,
|
|
isKnown: false,
|
|
priorityPoints: 10,
|
|
),
|
|
],
|
|
config: config,
|
|
);
|
|
});
|
|
|
|
test('markQuestionAsKnown sets streak to threshold and isKnown to true', () {
|
|
final updated = DeckService.markQuestionAsKnown(
|
|
deck: deck,
|
|
questionId: 'q1',
|
|
);
|
|
|
|
final question = updated.questions.firstWhere((q) => q.id == 'q1');
|
|
expect(question.consecutiveCorrect,
|
|
equals(config.requiredConsecutiveCorrect));
|
|
expect(question.isKnown, equals(true));
|
|
});
|
|
|
|
test('markQuestionAsNeedsPractice sets isKnown to false and streak to 0', () {
|
|
// First mark as known
|
|
var updated = DeckService.markQuestionAsKnown(
|
|
deck: deck,
|
|
questionId: 'q1',
|
|
);
|
|
|
|
// Then mark as needs practice
|
|
updated = DeckService.markQuestionAsNeedsPractice(
|
|
deck: updated,
|
|
questionId: 'q1',
|
|
);
|
|
|
|
final question = updated.questions.firstWhere((q) => q.id == 'q1');
|
|
expect(question.isKnown, equals(false));
|
|
expect(question.consecutiveCorrect, equals(0));
|
|
});
|
|
|
|
test('markQuestionAsNeedsPractice preserves priority', () {
|
|
final updated = DeckService.markQuestionAsNeedsPractice(
|
|
deck: deck,
|
|
questionId: 'q1',
|
|
);
|
|
|
|
final question = updated.questions.firstWhere((q) => q.id == 'q1');
|
|
expect(question.priorityPoints, equals(5));
|
|
});
|
|
|
|
test('manual override with needs practice ignores correctness', () {
|
|
final question = deck.questions.first;
|
|
|
|
// Answer correctly but mark as needs practice
|
|
final updated = DeckService.updateQuestionWithManualOverride(
|
|
question: question,
|
|
isCorrect: true,
|
|
userMarkedNeedsPractice: true,
|
|
config: config,
|
|
currentAttemptIndex: 0,
|
|
);
|
|
|
|
// Streak should not increment
|
|
expect(updated.consecutiveCorrect, equals(question.consecutiveCorrect));
|
|
|
|
// Priority should not decrease
|
|
expect(updated.priorityPoints, equals(question.priorityPoints));
|
|
|
|
// isKnown should not change
|
|
expect(updated.isKnown, equals(question.isKnown));
|
|
|
|
// But totalAttempts should increment
|
|
expect(updated.totalAttempts, equals(question.totalAttempts + 1));
|
|
});
|
|
|
|
test('manual override without needs practice follows normal flow', () {
|
|
final question = deck.questions.first;
|
|
|
|
final updated = DeckService.updateQuestionWithManualOverride(
|
|
question: question,
|
|
isCorrect: true,
|
|
userMarkedNeedsPractice: false,
|
|
config: config,
|
|
currentAttemptIndex: 0,
|
|
);
|
|
|
|
// Should behave like normal update
|
|
expect(updated.consecutiveCorrect, equals(question.consecutiveCorrect + 1));
|
|
expect(updated.priorityPoints,
|
|
equals(question.priorityPoints - config.priorityDecreaseOnCorrect));
|
|
});
|
|
});
|
|
}
|
|
|