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.
100 lines
2.9 KiB
100 lines
2.9 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('Reset 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: 5,
|
|
isKnown: true,
|
|
priorityPoints: 10,
|
|
lastAttemptIndex: 20,
|
|
totalCorrectAttempts: 15,
|
|
totalAttempts: 20,
|
|
),
|
|
Question(
|
|
id: 'q2',
|
|
prompt: 'Question 2',
|
|
answers: ['A', 'B'],
|
|
correctAnswerIndices: [0],
|
|
consecutiveCorrect: 2,
|
|
isKnown: false,
|
|
priorityPoints: 5,
|
|
lastAttemptIndex: 15,
|
|
totalCorrectAttempts: 8,
|
|
totalAttempts: 12,
|
|
),
|
|
],
|
|
config: config,
|
|
currentAttemptIndex: 25,
|
|
);
|
|
});
|
|
|
|
test('resetDeck resets all question states', () {
|
|
final reset = DeckService.resetDeck(deck: deck);
|
|
|
|
for (final question in reset.questions) {
|
|
expect(question.consecutiveCorrect, equals(0));
|
|
expect(question.isKnown, equals(false));
|
|
expect(question.priorityPoints, equals(0));
|
|
expect(question.lastAttemptIndex, equals(-1));
|
|
}
|
|
|
|
expect(reset.currentAttemptIndex, equals(0));
|
|
});
|
|
|
|
test('resetDeck preserves attempt counts by default', () {
|
|
final reset = DeckService.resetDeck(deck: deck);
|
|
|
|
expect(reset.questions[0].totalAttempts, equals(20));
|
|
expect(reset.questions[0].totalCorrectAttempts, equals(15));
|
|
expect(reset.questions[1].totalAttempts, equals(12));
|
|
expect(reset.questions[1].totalCorrectAttempts, equals(8));
|
|
});
|
|
|
|
test('resetDeck resets attempt counts when requested', () {
|
|
final reset = DeckService.resetDeck(
|
|
deck: deck,
|
|
resetAttemptCounts: true,
|
|
);
|
|
|
|
for (final question in reset.questions) {
|
|
expect(question.totalAttempts, equals(0));
|
|
expect(question.totalCorrectAttempts, equals(0));
|
|
}
|
|
});
|
|
|
|
test('resetDeck resets currentAttemptIndex to 0', () {
|
|
final reset = DeckService.resetDeck(deck: deck);
|
|
|
|
expect(reset.currentAttemptIndex, equals(0));
|
|
});
|
|
|
|
test('resetDeck preserves deck metadata', () {
|
|
final reset = DeckService.resetDeck(deck: deck);
|
|
|
|
expect(reset.id, equals(deck.id));
|
|
expect(reset.title, equals(deck.title));
|
|
expect(reset.description, equals(deck.description));
|
|
expect(reset.config, equals(deck.config));
|
|
});
|
|
});
|
|
}
|
|
|