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.
116 lines
3.0 KiB
116 lines
3.0 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';
|
|
|
|
void main() {
|
|
group('Deck', () {
|
|
late DeckConfig defaultConfig;
|
|
late List<Question> sampleQuestions;
|
|
|
|
setUp(() {
|
|
defaultConfig = const DeckConfig();
|
|
sampleQuestions = [
|
|
Question(
|
|
id: 'q1',
|
|
prompt: 'What is 2+2?',
|
|
answers: ['3', '4', '5'],
|
|
correctAnswerIndices: [1],
|
|
isKnown: true,
|
|
),
|
|
Question(
|
|
id: 'q2',
|
|
prompt: 'What is 3+3?',
|
|
answers: ['5', '6', '7'],
|
|
correctAnswerIndices: [1],
|
|
isKnown: false,
|
|
),
|
|
Question(
|
|
id: 'q3',
|
|
prompt: 'What is 4+4?',
|
|
answers: ['7', '8', '9'],
|
|
correctAnswerIndices: [1],
|
|
isKnown: true,
|
|
),
|
|
];
|
|
});
|
|
|
|
test('calculates numberOfQuestions correctly', () {
|
|
final deck = Deck(
|
|
id: 'deck1',
|
|
title: 'Math Deck',
|
|
description: 'Basic math',
|
|
questions: sampleQuestions,
|
|
config: defaultConfig,
|
|
);
|
|
|
|
expect(deck.numberOfQuestions, equals(3));
|
|
});
|
|
|
|
test('calculates knownCount correctly', () {
|
|
final deck = Deck(
|
|
id: 'deck1',
|
|
title: 'Math Deck',
|
|
description: 'Basic math',
|
|
questions: sampleQuestions,
|
|
config: defaultConfig,
|
|
);
|
|
|
|
expect(deck.knownCount, equals(2));
|
|
});
|
|
|
|
test('calculates practicePercentage correctly', () {
|
|
final deck = Deck(
|
|
id: 'deck1',
|
|
title: 'Math Deck',
|
|
description: 'Basic math',
|
|
questions: sampleQuestions,
|
|
config: defaultConfig,
|
|
);
|
|
|
|
expect(deck.practicePercentage, closeTo(66.67, 0.01));
|
|
});
|
|
|
|
test('practicePercentage is 0 for empty deck', () {
|
|
final deck = Deck(
|
|
id: 'deck1',
|
|
title: 'Empty Deck',
|
|
description: 'No questions',
|
|
questions: [],
|
|
config: defaultConfig,
|
|
);
|
|
|
|
expect(deck.practicePercentage, equals(0.0));
|
|
});
|
|
|
|
test('practicePercentage is 100 when all questions are known', () {
|
|
final allKnown = sampleQuestions.map((q) => q.copyWith(isKnown: true)).toList();
|
|
final deck = Deck(
|
|
id: 'deck1',
|
|
title: 'All Known',
|
|
description: 'All known',
|
|
questions: allKnown,
|
|
config: defaultConfig,
|
|
);
|
|
|
|
expect(deck.practicePercentage, equals(100.0));
|
|
});
|
|
|
|
test('copyWith creates new deck with updated fields', () {
|
|
final deck = Deck(
|
|
id: 'deck1',
|
|
title: 'Math Deck',
|
|
description: 'Basic math',
|
|
questions: sampleQuestions,
|
|
config: defaultConfig,
|
|
);
|
|
|
|
final updated = deck.copyWith(title: 'Updated Title');
|
|
expect(updated.title, equals('Updated Title'));
|
|
expect(updated.id, equals(deck.id));
|
|
expect(updated.questions, equals(deck.questions));
|
|
});
|
|
});
|
|
}
|
|
|