summaryrefslogtreecommitdiff
path: root/tests/unit/SpacedRepetitionModel/SRModel_schedule_test.cpp
blob: cd65154a69939f3b497318b60ffff614623ad4d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#include "SRModel_schedule_test.h"
#include "../../../src/utils/TimeProvider.h"

const double SRModel_schedule_Test::startE = StudySettings().initEasiness;

void SRModel_schedule_Test::SetUp()
{
    StudySettings::inst()->schedRandomness = StudySettings().schedRandomness;
    randomGenerator->setDouble(0.3);    
    cardName = createCard();
}

static const StudySettings* ss = StudySettings::inst();


// New
// Grades 1, 2, 3 not used

TEST_F(SRModel_schedule_Test, new_good) // Levels: 1 -> 2
    {
    setNewCard();
    schedule(4);
    checkStudy(StudyRecord::ShortLearning, startE, ss->unknownInterval);
    }

TEST_F(SRModel_schedule_Test, new_easy) // Levels: 1 -> 3
    {
    setNewCard();
    schedule(5);
    checkStudy(StudyRecord::LongLearning, startE, ss->learningInterval);
    }


// Short Learning

TEST_F(SRModel_schedule_Test, short_unknown)  // same level
    {
    setStudy({StudyRecord::ShortLearning, 4, startE, ss->unknownInterval});
    schedule(1);
    checkStudy(StudyRecord::ShortLearning, startE, ss->unknownInterval);
    }

TEST_F(SRModel_schedule_Test, short_incor)  // same level with longer interval
    {
    setStudy({StudyRecord::ShortLearning, 4, startE, ss->unknownInterval});
    schedule(2);
    checkStudy(StudyRecord::ShortLearning, startE, ss->incorrectInterval);
    }

        // grade 3 not used

TEST_F(SRModel_schedule_Test, short_good)   // Levels: 2 -> 3
    {
    setStudy({StudyRecord::ShortLearning, 4, startE, ss->unknownInterval});
    schedule(4);
    checkStudy(StudyRecord::LongLearning, startE, ss->learningInterval);
    }

TEST_F(SRModel_schedule_Test, short_easy)   // Levels: 2 -> repeat next day
    {
    setStudy({StudyRecord::ShortLearning, 4, startE, ss->unknownInterval});
    schedule(5);
    checkStudy(StudyRecord::Repeating, startE, ss->nextDayInterval);
    }


// Short learning from previous day:
// Is promoted directly to next day repeating

TEST_F(SRModel_schedule_Test, short_prevDay_difficult)
    {
    setStudy({StudyRecord::ShortLearning, 4, 2.5, ss->unknownInterval}, -1);
    schedule(3);
    checkStudy(StudyRecord::Repeating, 2.36, 2.18772);
    }

TEST_F(SRModel_schedule_Test, short_prevDay_good)
    {
    setStudy({StudyRecord::ShortLearning, 4, startE, ss->unknownInterval}, -1);
    schedule(4);
    checkStudy(StudyRecord::Repeating, startE, 2.3175);
    }

TEST_F(SRModel_schedule_Test, short_prevDay_easy)
    {
    setStudy({StudyRecord::ShortLearning, 4, 2.5, ss->unknownInterval}, -1);
    schedule(5);
    checkStudy(StudyRecord::Repeating, 2.6, 2.4102);
    }


// Long Learning

TEST_F(SRModel_schedule_Test, long_unknown)   // Levels: 3 -> 2
    {
    setStudy({StudyRecord::LongLearning, 4, startE, ss->learningInterval});
    schedule(1);
    checkStudy(StudyRecord::ShortLearning, startE, ss->unknownInterval);
    }

TEST_F(SRModel_schedule_Test, long_incor)   // Levels: 3 -> 2
    {
    setStudy({StudyRecord::LongLearning, 4, startE, ss->learningInterval});
    schedule(2);
    checkStudy(StudyRecord::ShortLearning, startE, ss->incorrectInterval);
    }

        // grade 3 not used

TEST_F(SRModel_schedule_Test, long_good)   // Levels: 3 -> repeat next day
    {
    setStudy({StudyRecord::LongLearning, 4, startE, ss->learningInterval});
    schedule(4);
    checkStudy(StudyRecord::Repeating, startE, ss->nextDayInterval);
    }

TEST_F(SRModel_schedule_Test, long_easy)   // Levels: 3 -> repeat in 2 days
    {
    setStudy({StudyRecord::LongLearning, 4, startE, ss->learningInterval});
    schedule(5);
    checkStudy(StudyRecord::Repeating, startE, ss->twoDaysInterval);
    }


// Long learning from previous day:
// Is promoted directly to next day repeating

TEST_F(SRModel_schedule_Test, long_prevDay_difficult)
    {
    setStudy({StudyRecord::LongLearning, 4, 2.5, ss->learningInterval}, -1);
    schedule(3);
    checkStudy(StudyRecord::Repeating, 2.36, 2.18772);
    }

TEST_F(SRModel_schedule_Test, long_prevDay_good)
    {
    setStudy({StudyRecord::LongLearning, 4, startE, ss->learningInterval}, -1);
    schedule(4);
    checkStudy(StudyRecord::Repeating, startE, 2.3175);
    }

TEST_F(SRModel_schedule_Test, long_prevDay_easy)
    {
    setStudy({StudyRecord::LongLearning, 4, 2.5, ss->learningInterval}, -1);
    schedule(5);
    checkStudy(StudyRecord::Repeating, 2.6, 2.4102);
    }


// First repeating day

TEST_F(SRModel_schedule_Test, firstRep_unknown)   // -> 2
    {
    setStudy({StudyRecord::Repeating, 4, startE, ss->nextDayInterval});
    schedule(1);
    checkStudy(StudyRecord::ShortLearning, startE, ss->unknownInterval);
    }

TEST_F(SRModel_schedule_Test, firstRep_incor)   // -> 2
    {
    setStudy({StudyRecord::Repeating, 4, startE, ss->nextDayInterval});
    schedule(2);
    checkStudy(StudyRecord::ShortLearning, startE, ss->incorrectInterval);
    }

TEST_F(SRModel_schedule_Test, firstRep_difficult)
    {
    setStudy({StudyRecord::Repeating, 4, startE, ss->nextDayInterval});
    schedule(3);
    checkStudy(StudyRecord::Repeating, 2.36, 2.18772);
    }

TEST_F(SRModel_schedule_Test, firstRep_good)
    {
    setStudy({StudyRecord::Repeating, 4, startE, ss->nextDayInterval});
    schedule(4);
    checkStudy(StudyRecord::Repeating, startE, 2.3175);
    }

TEST_F(SRModel_schedule_Test, firstRep_easy)
    {
    setStudy({StudyRecord::Repeating, 4, startE, ss->nextDayInterval});
    schedule(5);
    checkStudy(StudyRecord::Repeating, 2.6, 2.4102);
    }


// Normal repeating

TEST_F(SRModel_schedule_Test, repeat_unknown)
    {
    setStudy({StudyRecord::Repeating, 4, startE, 5});
    schedule(1);
    checkStudy(StudyRecord::ShortLearning, startE, ss->unknownInterval);
    }

TEST_F(SRModel_schedule_Test, repeat_incor)
    {
    setStudy({StudyRecord::Repeating, 4, startE, 5});
    schedule(2);
    checkStudy(StudyRecord::ShortLearning, startE, ss->incorrectInterval);
    }

TEST_F(SRModel_schedule_Test, repeat_difficult)
    {
    setStudy({StudyRecord::Repeating, 4, 2.5, 5});
    schedule(3);
    checkStudy(StudyRecord::Repeating, 2.36, 12.1540);
    }

TEST_F(SRModel_schedule_Test, repeat_good)
    {
    setStudy({StudyRecord::Repeating, 4, startE, 5});
    schedule(4);
    checkStudy(StudyRecord::Repeating, startE, 12.875);
    }

TEST_F(SRModel_schedule_Test, repeat_easy)
    {
    setStudy({StudyRecord::Repeating, 4, 2.5, 5});
    schedule(5);
    checkStudy(StudyRecord::Repeating, 2.6, 13.39);
    }


// Mature repeating

TEST_F(SRModel_schedule_Test, mature_difficult)
    {
    setStudy({StudyRecord::Repeating, 4, 3.1, 23});
    schedule(3);
    checkStudy(StudyRecord::Repeating, 2.96, 70.1224);
    }

TEST_F(SRModel_schedule_Test, mature_good)
    {
    setStudy({StudyRecord::Repeating, 4, 3.1, 23});
    schedule(4);
    checkStudy(StudyRecord::Repeating, 3.1, 73.439);
    }


// Re-learning unknown and incorrect cards

TEST_F(SRModel_schedule_Test, unknown_incor)
    {
    setStudy({StudyRecord::ShortLearning, 1, startE, ss->unknownInterval});
    schedule(2);
    checkStudy(StudyRecord::ShortLearning, startE, ss->incorrectInterval);
    }

TEST_F(SRModel_schedule_Test, incor_unknown)
    {
    setStudy({StudyRecord::ShortLearning, 2, startE, ss->incorrectInterval});
    schedule(1);
    checkStudy(StudyRecord::ShortLearning, startE, ss->unknownInterval);
    }

TEST_F(SRModel_schedule_Test, unknown_good)
    {
    setStudy({StudyRecord::ShortLearning, 1, startE, ss->unknownInterval});
    schedule(4);
    checkStudy(StudyRecord::LongLearning, startE, ss->learningInterval);
    }

TEST_F(SRModel_schedule_Test, incor_good)
    {
    setStudy({StudyRecord::ShortLearning, 2, startE, ss->incorrectInterval});
    schedule(4);
    checkStudy(StudyRecord::LongLearning, startE, ss->learningInterval);
    }


void SRModel_schedule_Test::setNewCard()
{
    pack.addStudyRecord(cardName, StudyRecord());
}

void SRModel_schedule_Test::setStudy(StudyRecord study, double daysDelta)
{
    study.date = timeFromDelta(daysDelta);
    pack.addStudyRecord(cardName, study);
}

QDateTime SRModel_schedule_Test::timeFromDelta(double daysDelta)
{
    return TimeProvider::get().addSecs((int)(daysDelta * 24 * 60 * 60));
}

void SRModel_schedule_Test::schedule(int grade)
{
    this->grade = grade;
    model.scheduleCard(grade);
}

void SRModel_schedule_Test::checkStudy(int expLevel, double expEasiness,
            double expInterval)
{
    StudyRecord newStudy = pack.getStudyRecord(cardName);
    ASSERT_EQ(grade, newStudy.grade);
    ASSERT_EQ(expLevel, newStudy.level);
    ASSERT_DOUBLE_EQ(expEasiness, newStudy.easiness);
    ASSERT_NEAR(expInterval, newStudy.interval, 0.00000001);
}