summaryrefslogtreecommitdiff
path: root/tests/unit/SpacedRepetitionModel/SRModel_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/SpacedRepetitionModel/SRModel_test.cpp')
-rw-r--r--tests/unit/SpacedRepetitionModel/SRModel_test.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/unit/SpacedRepetitionModel/SRModel_test.cpp b/tests/unit/SpacedRepetitionModel/SRModel_test.cpp
new file mode 100644
index 0000000..420dfa7
--- /dev/null
+++ b/tests/unit/SpacedRepetitionModel/SRModel_test.cpp
@@ -0,0 +1,67 @@
+#include "SRModel_test.h"
+#include "../../common/printQtTypes.h"
+#include "../../../src/dictionary/DicRecord.h"
+#include "../../../src/dictionary/Card.h"
+#include "../../../src/study/StudySettings.h"
+#include "../../mocks/RandomGenerator_mock.h"
+
+SRModelTest::SRModelTest():
+ recordId(0),
+ pack(&dict),
+ randomGenerator(new MockRandomGenerator),
+ model(&pack, randomGenerator)
+{
+ field1 = new Field("English", "Normal");
+ field2 = new Field("Russian", "Normal");
+ pack.addField(field1);
+ pack.addField(field2);
+ dict.addCardPack(&pack);
+}
+
+void SRModelTest::SetUp()
+{
+ QCoreApplication::setOrganizationName("freshmemory");
+ QCoreApplication::setApplicationName("freshmemory");
+ QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, "");
+ StudySettings::inst()->load();
+}
+
+void SRModelTest::TearDown()
+{
+ delete field1;
+ delete field2;
+}
+
+TEST_F(SRModelTest, EmptyStats)
+ {
+ ASSERT_EQ(0, model.estimatedNewReviewedCardsToday());
+ ASSERT_EQ(0, model.countTodayRemainingCards());
+ }
+
+TEST_F(SRModelTest, FirstStudy)
+ {
+ QString cardName = createCard();
+ StudyRecord newStudy = pack.getStudyRecord(cardName);
+
+ ASSERT_EQ(StudyRecord::Unknown, newStudy.grade);
+ ASSERT_DOUBLE_EQ(StudySettings::inst()->initEasiness, newStudy.easiness);
+ ASSERT_DOUBLE_EQ(0, newStudy.interval);
+ }
+
+QString SRModelTest::createCard()
+{
+ addRecord();
+ pack.generateQuestions();
+ return model.getCurCard()->getQuestion();
+}
+
+QString SRModelTest::addRecord()
+{
+ DicRecord* record = new DicRecord;
+ QString recordName = QString::number(recordId);
+ record->setField("English", recordName);
+ record->setField("Russian", "Odin");
+ recordId++;
+ dict.addRecord(record);
+ return recordName;
+}