Changeset View
Changeset View
Standalone View
Standalone View
autotests/testentrytest.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 by Hartmut Riesenbeck <hartmut.riesenbeck@gmx.de> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | #include "testentrytest.h" | ||||
21 | | ||||
22 | #include "testentry.h" | ||||
23 | #include "prefs.h" | ||||
24 | #include <QTest> | ||||
25 | | ||||
26 | namespace TestEntryTests{ | ||||
27 | | ||||
28 | void TestEntryTest::initTestCase() | ||||
29 | { | ||||
30 | /* | ||||
31 | * A TestEntry object is created with following grade levels set: | ||||
32 | * translation index 0 | ||||
33 | * base - grade 1 | ||||
34 | * article - grade 2 | ||||
35 | * conjugations - grades 3, 4 and 5 | ||||
36 | * comparatives - grades 6 and 7 | ||||
37 | * translation index 1 | ||||
38 | * base - grade 0 | ||||
39 | * article - grade 0 | ||||
40 | * conjugations - grades 0, 0 and 0 | ||||
41 | * comparatives - grades 0, 0 and 0 | ||||
42 | */ | ||||
43 | m_gradeExpression = makeKEduVocExpressionGrade(); | ||||
44 | m_gradeTestEntry = makeTestEntry(m_gradeExpression); | ||||
45 | | ||||
46 | /* | ||||
47 | * A TestEntry object is created with following pregrade levels set: | ||||
48 | * translation index 0 | ||||
49 | * base - pregrad 1 | ||||
50 | * article - pregrad 2 | ||||
51 | * conjugations - pregrads 3, 4 and 5 | ||||
52 | * comparatives - pregrads 6 and 7 | ||||
53 | * translation index 1 | ||||
54 | * base - pregrad 0 | ||||
55 | * article - pregrad 0 | ||||
56 | * conjugations - pregrads 0, 0 and 0 | ||||
57 | * comparatives - pregrads 0, 0 and 0 | ||||
58 | */ | ||||
59 | m_preGradeExpression = makeKEduVocExpressionPreGrade(); | ||||
60 | m_preGradeTestEntry = makeTestEntry(m_preGradeExpression); | ||||
61 | } | ||||
62 | | ||||
63 | | ||||
64 | KEduVocExpression *TestEntryTest::makeKEduVocExpressionGrade() | ||||
65 | { | ||||
66 | KEduVocExpression *expression = new KEduVocExpression; | ||||
67 | expression->setTranslation(0, QStringLiteral("translation 0")); | ||||
68 | KEduVocTranslation *translation0 = expression->translation(0); | ||||
69 | | ||||
70 | translation0->setGrade(KV_LEV1_GRADE); | ||||
71 | | ||||
72 | KEduVocText text; | ||||
73 | text.setGrade(KV_LEV2_GRADE); | ||||
74 | translation0->setArticle(text); | ||||
75 | | ||||
76 | KEduVocConjugation conjugation0; | ||||
77 | text.setText(QStringLiteral("conjugation 00")); | ||||
78 | text.setGrade(KV_LEV3_GRADE); | ||||
79 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
80 | text.setText(QStringLiteral("conjugation 01")); | ||||
81 | text.setGrade(KV_LEV4_GRADE); | ||||
82 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
83 | text.setText(QStringLiteral("conjugation 03")); | ||||
84 | text.setGrade(KV_LEV5_GRADE); | ||||
85 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | ||||
86 | | KEduVocWordFlag::Third | ||||
87 | | KEduVocWordFlag::Neuter); | ||||
88 | translation0->setConjugation(QStringLiteral("tense"), conjugation0); | ||||
89 | | ||||
90 | text.setText(QStringLiteral("comparative 0")); | ||||
91 | text.setGrade(KV_LEV6_GRADE); | ||||
92 | translation0->setComparativeForm(text); | ||||
93 | | ||||
94 | text.setText(QStringLiteral("superlative 0")); | ||||
95 | text.setGrade(KV_LEV7_GRADE); | ||||
96 | translation0->setSuperlativeForm(text); | ||||
97 | | ||||
98 | | ||||
99 | expression->setTranslation(1, QStringLiteral("translation 1")); | ||||
100 | KEduVocTranslation *translation1 = expression->translation(1); | ||||
101 | | ||||
102 | translation1->setArticle(KEduVocText()); | ||||
103 | | ||||
104 | KEduVocConjugation conjugation1; | ||||
105 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), | ||||
106 | KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
107 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), | ||||
108 | KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
109 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), | ||||
110 | KEduVocWordFlag::Singular | KEduVocWordFlag::Third | ||||
111 | | KEduVocWordFlag::Neuter); | ||||
112 | translation1->setConjugation(QStringLiteral("tense"), conjugation1); | ||||
113 | | ||||
114 | translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1"))); | ||||
115 | translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1"))); | ||||
116 | | ||||
117 | return expression; | ||||
118 | } | ||||
119 | | ||||
120 | | ||||
121 | KEduVocExpression *TestEntryTest::makeKEduVocExpressionPreGrade() | ||||
122 | { | ||||
123 | KEduVocExpression *expression = new KEduVocExpression; | ||||
124 | expression->setTranslation(0, QStringLiteral("translation 0")); | ||||
125 | KEduVocTranslation *translation0 = expression->translation(0); | ||||
126 | | ||||
127 | translation0->setPreGrade(KV_LEV1_GRADE); | ||||
128 | | ||||
129 | KEduVocText text; | ||||
130 | text.setPreGrade(KV_LEV2_GRADE); | ||||
131 | translation0->setArticle(text); | ||||
132 | | ||||
133 | KEduVocConjugation conjugation0; | ||||
134 | text.setText(QStringLiteral("conjugation 00")); | ||||
135 | text.setPreGrade(KV_LEV3_GRADE); | ||||
136 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
137 | text.setText(QStringLiteral("conjugation 01")); | ||||
138 | text.setPreGrade(KV_LEV4_GRADE); | ||||
139 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
140 | text.setText(QStringLiteral("conjugation 03")); | ||||
141 | text.setPreGrade(KV_LEV5_GRADE); | ||||
142 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | ||||
143 | | KEduVocWordFlag::Third | ||||
144 | | KEduVocWordFlag::Neuter); | ||||
145 | translation0->setConjugation(QStringLiteral("tense"), conjugation0); | ||||
146 | | ||||
147 | text.setText(QStringLiteral("comparative 0")); | ||||
148 | text.setPreGrade(KV_LEV6_GRADE); | ||||
149 | translation0->setComparativeForm(text); | ||||
150 | | ||||
151 | text.setText(QStringLiteral("superlative 0")); | ||||
152 | text.setPreGrade(KV_LEV7_GRADE); | ||||
153 | translation0->setSuperlativeForm(text); | ||||
154 | | ||||
155 | | ||||
156 | expression->setTranslation(1, QStringLiteral("translation 1")); | ||||
157 | KEduVocTranslation *translation1 = expression->translation(1); | ||||
158 | | ||||
159 | translation1->setArticle(KEduVocText()); | ||||
160 | | ||||
161 | KEduVocConjugation conjugation1; | ||||
162 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), | ||||
163 | KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
164 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), | ||||
165 | KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
166 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), | ||||
167 | KEduVocWordFlag::Singular | KEduVocWordFlag::Third | ||||
168 | | KEduVocWordFlag::Neuter); | ||||
169 | | ||||
170 | translation1->setConjugation(QStringLiteral("tense"), conjugation1); | ||||
171 | translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1"))); | ||||
172 | translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1"))); | ||||
173 | | ||||
174 | return expression; | ||||
175 | } | ||||
176 | | ||||
177 | | ||||
178 | TestEntry *TestEntryTest::makeTestEntry(KEduVocExpression *expression) | ||||
179 | { | ||||
180 | TestEntry *testEntry = new TestEntry(expression); | ||||
181 | testEntry->setLanguageTo(0); | ||||
182 | testEntry->setLanguageFrom(1); | ||||
183 | testEntry->setConjugationTense(QStringLiteral("tense")); | ||||
184 | testEntry->setConjugationPronouns({ | ||||
185 | KEduVocWordFlag::Singular | KEduVocWordFlag::First, | ||||
186 | KEduVocWordFlag::Singular | KEduVocWordFlag::Second, | ||||
187 | KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | ||||
188 | }); | ||||
189 | | ||||
190 | return testEntry; | ||||
191 | } | ||||
192 | | ||||
193 | | ||||
194 | void TestEntryTest::cleanupTestCase() | ||||
195 | { | ||||
196 | delete m_gradeTestEntry; | ||||
197 | delete m_gradeExpression; | ||||
198 | delete m_preGradeTestEntry; | ||||
199 | delete m_preGradeExpression; | ||||
200 | } | ||||
201 | | ||||
202 | | ||||
203 | void TestEntryTest::test_practiceModeDependentMinGrade_written() | ||||
204 | { | ||||
205 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
206 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
207 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
208 | } | ||||
209 | | ||||
210 | | ||||
211 | void TestEntryTest::test_practiceModeDependentMinGrade_gender() | ||||
212 | { | ||||
213 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
214 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
215 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
216 | } | ||||
217 | | ||||
218 | | ||||
219 | void TestEntryTest::test_practiceModeDependentMinGrade_conjugation() | ||||
220 | { | ||||
221 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
222 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
223 | static_cast<grade_t>(KV_LEV3_GRADE)); | ||||
224 | } | ||||
225 | | ||||
226 | | ||||
227 | void TestEntryTest::test_practiceModeDependentMinGrade_comparsion() | ||||
228 | { | ||||
229 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
230 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
231 | static_cast<grade_t>(KV_LEV6_GRADE)); | ||||
232 | } | ||||
233 | | ||||
234 | | ||||
235 | void TestEntryTest::test_practiceModeDependentMaxGrade_written() | ||||
236 | { | ||||
237 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
238 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
239 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
240 | } | ||||
241 | | ||||
242 | | ||||
243 | void TestEntryTest::test_practiceModeDependentMaxGrade_gender() | ||||
244 | { | ||||
245 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
246 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
247 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
248 | } | ||||
249 | | ||||
250 | | ||||
251 | void TestEntryTest::test_practiceModeDependentMaxGrade_conjugation() | ||||
252 | { | ||||
253 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
254 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
255 | static_cast<grade_t>(KV_LEV5_GRADE)); | ||||
256 | } | ||||
257 | | ||||
258 | | ||||
259 | void TestEntryTest::test_practiceModeDependentMaxGrade_comparsion() | ||||
260 | { | ||||
261 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
262 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
263 | static_cast<grade_t>(KV_LEV7_GRADE)); | ||||
264 | } | ||||
265 | | ||||
266 | | ||||
267 | void TestEntryTest::test_practiceModeDependentMinPreGrade_written() | ||||
268 | { | ||||
269 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
270 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
271 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
272 | } | ||||
273 | | ||||
274 | | ||||
275 | void TestEntryTest::test_practiceModeDependentMinPreGrade_gender() | ||||
276 | { | ||||
277 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
278 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
279 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
280 | } | ||||
281 | | ||||
282 | | ||||
283 | void TestEntryTest::test_practiceModeDependentMinPreGrade_conjugation() | ||||
284 | { | ||||
285 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
286 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
287 | static_cast<grade_t>(KV_LEV3_GRADE)); | ||||
288 | } | ||||
289 | | ||||
290 | | ||||
291 | void TestEntryTest::test_practiceModeDependentMinPreGrade_comparsion() | ||||
292 | { | ||||
293 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
294 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
295 | static_cast<grade_t>(KV_LEV6_GRADE)); | ||||
296 | } | ||||
297 | | ||||
298 | | ||||
299 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_written() | ||||
300 | { | ||||
301 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
302 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
303 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
304 | } | ||||
305 | | ||||
306 | | ||||
307 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_gender() | ||||
308 | { | ||||
309 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
310 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
311 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
312 | } | ||||
313 | | ||||
314 | | ||||
315 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_conjugation() | ||||
316 | { | ||||
317 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
318 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
319 | static_cast<grade_t>(KV_LEV5_GRADE)); | ||||
320 | } | ||||
321 | | ||||
322 | | ||||
323 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_comparsion() | ||||
324 | { | ||||
325 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
326 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
327 | static_cast<grade_t>(KV_LEV7_GRADE)); | ||||
328 | } | ||||
329 | | ||||
330 | } | ||||
331 | | ||||
332 | QTEST_MAIN(TestEntryTests::TestEntryTest) |