diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -53,3 +53,7 @@ # allpass1test allpass2test ) +parley_non_gui_unittests( + testentrytest + sessionmanagerfixedtest +) diff --git a/autotests/sessionmanagerfixedtest.h b/autotests/sessionmanagerfixedtest.h new file mode 100644 --- /dev/null +++ b/autotests/sessionmanagerfixedtest.h @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2019 by Hartmut Riesenbeck * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef SESSIONMANAGERFIXEDTEST_H +#define SESSIONMANAGERFIXEDTEST_H + +#include + +class KEduVocDocument; + +namespace SessionManagerFixedTests { +/** @file + * \brief SessionManagerFixedTest test application + * Various tests for SessionManagerFixed class. + * @author Hartmut Riesenbeck + */ + +class SessionManagerFixedTest : public QObject +{ +Q_OBJECT + +private slots: + void test_maximumNumberOfNewWordsPerSession_written(); + void test_maximumNumberOfNewWordsPerSession_gender(); + void test_maximumNumberOfNewWordsPerSession_conjugation(); + void test_maximumNumberOfNewWordsPerSession_comparsion(); + +private: + void setupBasicPreferences() const; + void initDocumentPracticeModeDependent(KEduVocDocument &doc, int nEntries) const; + +}; +} + +#endif // SESSIONMANAGERFIXEDTEST_H + diff --git a/autotests/sessionmanagerfixedtest.cpp b/autotests/sessionmanagerfixedtest.cpp new file mode 100644 --- /dev/null +++ b/autotests/sessionmanagerfixedtest.cpp @@ -0,0 +1,246 @@ +/*************************************************************************** + * Copyright (C) 2019 by Hartmut Riesenbeck * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "sessionmanagerfixedtest.h" + +#include "sessionmanagerfixed.h" +#include "prefs.h" +#include "documentsettings.h" +#include +#include +#include + + +namespace SessionManagerFixedTests +{ + +void SessionManagerFixedTest::setupBasicPreferences() const +{ + Prefs::setLearningLanguage(0); + Prefs::setKnownLanguage(1); + Prefs::setPracticeDirection(Prefs::EnumPracticeDirection::KnownToLearning); + Prefs::setAllowImageInsteadOfWord(false); + Prefs::setExpire(false); + Prefs::setWordTypesInPracticeEnabled(false); + Prefs::setBlock(true); + Prefs::setPracticeMinimumWrongCount(0); + Prefs::setPracticeMaximumWrongCount(1000); + Prefs::setPracticeMinimumTimesAsked(0); + Prefs::setPracticeMaximumTimesAsked(1000); + Prefs::setPracticeMinimumGrade(0); + Prefs::setPracticeMaximumGrade(7); + Prefs::setSessionMaxSize(20); +} + + +void SessionManagerFixedTest::initDocumentPracticeModeDependent(KEduVocDocument &doc, + int nEntries) const +{ + KEduVocWordType *root = doc.wordTypeContainer(); + KEduVocWordType *noun = new KEduVocWordType(QStringLiteral("Noun"), root); + noun->setWordType(KEduVocWordFlag::Noun); + root->appendChildContainer(noun); + + KEduVocWordType *nounChild = new KEduVocWordType(QStringLiteral("Masculine"), noun); + nounChild->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Masculine); + noun->appendChildContainer(nounChild); + nounChild = new KEduVocWordType(QStringLiteral("Feminine"), noun); + nounChild->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Feminine); + noun->appendChildContainer(nounChild); + nounChild = new KEduVocWordType(QStringLiteral("Neuter"), noun); + nounChild->setWordType(KEduVocWordFlag::Noun | KEduVocWordFlag::Neuter); + noun->appendChildContainer(nounChild); + + KEduVocWordType *verb = new KEduVocWordType(QStringLiteral("Verb"), root); + verb->setWordType(KEduVocWordFlag::Verb); + root->appendChildContainer(verb); + + KEduVocWordType *adjective = new KEduVocWordType(QStringLiteral("Adjective"), root); + adjective->setWordType(KEduVocWordFlag::Adjective); + root->appendChildContainer(adjective); + + KEduVocLesson *lesson = new KEduVocLesson(QStringLiteral("Lesson 1"), doc.lesson()); + doc.lesson()->appendChildContainer(lesson); + + doc.appendIdentifier(); + doc.appendIdentifier(); + doc.identifier(0).setName(QStringLiteral("Languge 0")); + doc.identifier(0).setLocale(QStringLiteral("l0")); + doc.identifier(1).setName(QStringLiteral("Languge 1")); + doc.identifier(1).setLocale(QStringLiteral("l1")); + + for (int i = 0; i < nEntries ; i++) { + KEduVocExpression *expression = new KEduVocExpression; + expression->setTranslation(0, QStringLiteral("translation 0 word %1").arg(i)); + expression->setTranslation(1, QStringLiteral("translation 1 word %1").arg(i)); + lesson->appendEntry(expression); + + if (Prefs::practiceMode() == Prefs::EnumPracticeMode::GenderPractice) { + auto container = doc.wordTypeContainer()->childOfType(KEduVocWordFlag::Noun + | KEduVocWordFlag::Masculine); + expression->translation(0)->setWordType(container); + expression->translation(1)->setWordType(container); + + // Set top entry vocabel to already practiced and leave article as new + expression->translation(0)->setGrade(KV_LEV1_GRADE); + expression->translation(1)->setGrade(KV_LEV1_GRADE); + } + + if (Prefs::practiceMode() == Prefs::EnumPracticeMode::ConjugationPractice) { + KEduVocConjugation conjugation0; + conjugation0.setConjugation(KEduVocText(QStringLiteral("conjugation %1 00").arg(i)), + KEduVocWordFlag::Singular | KEduVocWordFlag::First); + conjugation0.setConjugation(KEduVocText(QStringLiteral("conjugation %1 01").arg(i)), + KEduVocWordFlag::Singular | KEduVocWordFlag::Second); + conjugation0.setConjugation(KEduVocText(QStringLiteral("conjugation %1 03").arg(i)), + KEduVocWordFlag::Singular | KEduVocWordFlag::Third + | KEduVocWordFlag::Neuter); + expression->translation(0)->setConjugation(QStringLiteral("tense"), conjugation0); + + KEduVocConjugation conjugation1; + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation %1 10").arg(i)), + KEduVocWordFlag::Singular | KEduVocWordFlag::First); + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation %1 11").arg(i)), + KEduVocWordFlag::Singular | KEduVocWordFlag::Second); + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation %1 13").arg(i)), + KEduVocWordFlag::Singular | KEduVocWordFlag::Third + | KEduVocWordFlag::Neuter); + expression->translation(1)->setConjugation(QStringLiteral("tense"), conjugation1); + + auto container = doc.wordTypeContainer()->childOfType(KEduVocWordFlag::Verb); + expression->translation(0)->setWordType(container); + expression->translation(1)->setWordType(container); + + // Set top level entry to already practiced and leave conjugations as new + expression->translation(0)->setGrade(KV_LEV1_GRADE); + expression->translation(1)->setGrade(KV_LEV1_GRADE); + } + + if (Prefs::practiceMode() == Prefs::EnumPracticeMode::ComparisonPractice) { + expression->translation(0)->setComparativeForm( + KEduVocText(QStringLiteral("comparative %1 0").arg(i))); + expression->translation(0)->setSuperlativeForm( + KEduVocText(QStringLiteral("superlative %1 0").arg(i))); + expression->translation(1)->setComparativeForm( + KEduVocText(QStringLiteral("comparative %1 1").arg(i))); + expression->translation(1)->setSuperlativeForm( + KEduVocText(QStringLiteral("superlative %1 1").arg(i))); + + auto container = doc.wordTypeContainer()->childOfType(KEduVocWordFlag::Adjective); + expression->translation(0)->setWordType(container); + expression->translation(1)->setWordType(container); + + // Set top level entry to already practiced and leave comparative forms as new + expression->translation(0)->setGrade(KV_LEV1_GRADE); + expression->translation(1)->setGrade(KV_LEV1_GRADE); + } + } + + doc.setUrl(QUrl::fromLocalFile(QStringLiteral("dummy_fquJ4CM7.kvtml"))); + doc.setModified(false); +} + + +void SessionManagerFixedTest::test_maximumNumberOfNewWordsPerSession_written() +{ + constexpr int MAX_NUMBER_OF_NEW_WORDS = 5; + + setupBasicPreferences(); + Prefs::setSessionMaxNewWords(MAX_NUMBER_OF_NEW_WORDS); + Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); + + KEduVocDocument doc; + // Fill document with 10 unpracticed entries appropriate to current practice mode + initDocumentPracticeModeDependent(doc, 10); + + QWidget dummy; + Practice::SessionManagerFixed sessionManager(&dummy); + sessionManager.setDocument(&doc); + + QCOMPARE(sessionManager.allEntryCount(), MAX_NUMBER_OF_NEW_WORDS); +} + + +void SessionManagerFixedTest::test_maximumNumberOfNewWordsPerSession_gender() +{ + constexpr int MAX_NUMBER_OF_NEW_WORDS = 5; + + setupBasicPreferences(); + Prefs::setSessionMaxNewWords(MAX_NUMBER_OF_NEW_WORDS); + Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); + + KEduVocDocument doc; + // Fill document with 10 unpracticed entries appropriate to current practice mode + initDocumentPracticeModeDependent(doc, 10); + + QWidget dummy; + Practice::SessionManagerFixed sessionManager(&dummy); + sessionManager.setDocument(&doc); + + QCOMPARE(sessionManager.allEntryCount(), MAX_NUMBER_OF_NEW_WORDS); +} + + +void SessionManagerFixedTest::test_maximumNumberOfNewWordsPerSession_conjugation() +{ + constexpr int MAX_NUMBER_OF_NEW_WORDS = 5; + + setupBasicPreferences(); + Prefs::setSessionMaxNewWords(MAX_NUMBER_OF_NEW_WORDS); + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); + + KEduVocDocument doc; + // Fill document with 10 unpracticed entries appropriate to current practice mode + initDocumentPracticeModeDependent(doc, 10); + + DocumentSettings documentSettings(doc.url().url() + QStringLiteral("0")); + documentSettings.load(); + documentSettings.setConjugationTenses({QStringLiteral("tense")}); + documentSettings.save(); + + QWidget dummy; + Practice::SessionManagerFixed sessionManager(&dummy); + sessionManager.setDocument(&doc); + + QCOMPARE(sessionManager.allEntryCount(), MAX_NUMBER_OF_NEW_WORDS); +} + + +void SessionManagerFixedTest::test_maximumNumberOfNewWordsPerSession_comparsion() +{ + constexpr int MAX_NUMBER_OF_NEW_WORDS = 5; + + setupBasicPreferences(); + Prefs::setSessionMaxNewWords(MAX_NUMBER_OF_NEW_WORDS); + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); + + KEduVocDocument doc; + // Fill document with 10 unpracticed entries appropriate to current practice mode + initDocumentPracticeModeDependent(doc, 10); + + QWidget dummy; + Practice::SessionManagerFixed sessionManager(&dummy); + sessionManager.setDocument(&doc); + + QCOMPARE(sessionManager.allEntryCount(), MAX_NUMBER_OF_NEW_WORDS); +} + +} + +QTEST_MAIN(SessionManagerFixedTests::SessionManagerFixedTest) diff --git a/autotests/testentrytest.h b/autotests/testentrytest.h new file mode 100644 --- /dev/null +++ b/autotests/testentrytest.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (C) 2019 by Hartmut Riesenbeck * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef TESTENTRYTEST_H +#define TESTENTRYTEST_H + +#include + + +class KEduVocExpression; +class TestEntry; + + +namespace TestEntryTests { +/** @file + * \brief TestEntry test application + * Various tests for TestEntry class. + * @author Hartmut Riesenbeck + */ + +class TestEntryTest : public QObject +{ +Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + void test_practiceModeDependentMinGrade_written(); + void test_practiceModeDependentMinGrade_gender(); + void test_practiceModeDependentMinGrade_conjugation(); + void test_practiceModeDependentMinGrade_comparsion(); + void test_practiceModeDependentMaxGrade_written(); + void test_practiceModeDependentMaxGrade_gender(); + void test_practiceModeDependentMaxGrade_conjugation(); + void test_practiceModeDependentMaxGrade_comparsion(); + void test_practiceModeDependentMinPreGrade_written(); + void test_practiceModeDependentMinPreGrade_gender(); + void test_practiceModeDependentMinPreGrade_conjugation(); + void test_practiceModeDependentMinPreGrade_comparsion(); + void test_practiceModeDependentMaxPreGrade_written(); + void test_practiceModeDependentMaxPreGrade_gender(); + void test_practiceModeDependentMaxPreGrade_conjugation(); + void test_practiceModeDependentMaxPreGrade_comparsion(); + +private: + KEduVocExpression *makeKEduVocExpressionGrade(); + KEduVocExpression *makeKEduVocExpressionPreGrade(); + TestEntry *makeTestEntry(KEduVocExpression *expression); + +private: + KEduVocExpression *m_gradeExpression = nullptr; + TestEntry *m_gradeTestEntry = nullptr; + KEduVocExpression *m_preGradeExpression = nullptr; + TestEntry *m_preGradeTestEntry = nullptr; +}; +} + +#endif // TESTENTRYTEST_H + diff --git a/autotests/testentrytest.cpp b/autotests/testentrytest.cpp new file mode 100644 --- /dev/null +++ b/autotests/testentrytest.cpp @@ -0,0 +1,332 @@ +/*************************************************************************** + * Copyright (C) 2019 by Hartmut Riesenbeck * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "testentrytest.h" + +#include "testentry.h" +#include "prefs.h" +#include + +namespace TestEntryTests{ + +void TestEntryTest::initTestCase() +{ + /* + * A TestEntry object is created with following grade levels set: + * translation index 0 + * base - grade 1 + * article - grade 2 + * conjugations - grades 3, 4 and 5 + * comparatives - grades 6 and 7 + * translation index 1 + * base - grade 0 + * article - grade 0 + * conjugations - grades 0, 0 and 0 + * comparatives - grades 0, 0 and 0 + */ + m_gradeExpression = makeKEduVocExpressionGrade(); + m_gradeTestEntry = makeTestEntry(m_gradeExpression); + + /* + * A TestEntry object is created with following pregrade levels set: + * translation index 0 + * base - pregrad 1 + * article - pregrad 2 + * conjugations - pregrads 3, 4 and 5 + * comparatives - pregrads 6 and 7 + * translation index 1 + * base - pregrad 0 + * article - pregrad 0 + * conjugations - pregrads 0, 0 and 0 + * comparatives - pregrads 0, 0 and 0 + */ + m_preGradeExpression = makeKEduVocExpressionPreGrade(); + m_preGradeTestEntry = makeTestEntry(m_preGradeExpression); +} + + +KEduVocExpression *TestEntryTest::makeKEduVocExpressionGrade() +{ + KEduVocExpression *expression = new KEduVocExpression; + expression->setTranslation(0, QStringLiteral("translation 0")); + KEduVocTranslation *translation0 = expression->translation(0); + + translation0->setGrade(KV_LEV1_GRADE); + + KEduVocText text; + text.setGrade(KV_LEV2_GRADE); + translation0->setArticle(text); + + KEduVocConjugation conjugation0; + text.setText(QStringLiteral("conjugation 00")); + text.setGrade(KV_LEV3_GRADE); + conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First); + text.setText(QStringLiteral("conjugation 01")); + text.setGrade(KV_LEV4_GRADE); + conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second); + text.setText(QStringLiteral("conjugation 03")); + text.setGrade(KV_LEV5_GRADE); + conjugation0.setConjugation(text, KEduVocWordFlag::Singular + | KEduVocWordFlag::Third + | KEduVocWordFlag::Neuter); + translation0->setConjugation(QStringLiteral("tense"), conjugation0); + + text.setText(QStringLiteral("comparative 0")); + text.setGrade(KV_LEV6_GRADE); + translation0->setComparativeForm(text); + + text.setText(QStringLiteral("superlative 0")); + text.setGrade(KV_LEV7_GRADE); + translation0->setSuperlativeForm(text); + + + expression->setTranslation(1, QStringLiteral("translation 1")); + KEduVocTranslation *translation1 = expression->translation(1); + + translation1->setArticle(KEduVocText()); + + KEduVocConjugation conjugation1; + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), + KEduVocWordFlag::Singular | KEduVocWordFlag::First); + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), + KEduVocWordFlag::Singular | KEduVocWordFlag::Second); + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), + KEduVocWordFlag::Singular | KEduVocWordFlag::Third + | KEduVocWordFlag::Neuter); + translation1->setConjugation(QStringLiteral("tense"), conjugation1); + + translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1"))); + translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1"))); + + return expression; +} + + +KEduVocExpression *TestEntryTest::makeKEduVocExpressionPreGrade() +{ + KEduVocExpression *expression = new KEduVocExpression; + expression->setTranslation(0, QStringLiteral("translation 0")); + KEduVocTranslation *translation0 = expression->translation(0); + + translation0->setPreGrade(KV_LEV1_GRADE); + + KEduVocText text; + text.setPreGrade(KV_LEV2_GRADE); + translation0->setArticle(text); + + KEduVocConjugation conjugation0; + text.setText(QStringLiteral("conjugation 00")); + text.setPreGrade(KV_LEV3_GRADE); + conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First); + text.setText(QStringLiteral("conjugation 01")); + text.setPreGrade(KV_LEV4_GRADE); + conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second); + text.setText(QStringLiteral("conjugation 03")); + text.setPreGrade(KV_LEV5_GRADE); + conjugation0.setConjugation(text, KEduVocWordFlag::Singular + | KEduVocWordFlag::Third + | KEduVocWordFlag::Neuter); + translation0->setConjugation(QStringLiteral("tense"), conjugation0); + + text.setText(QStringLiteral("comparative 0")); + text.setPreGrade(KV_LEV6_GRADE); + translation0->setComparativeForm(text); + + text.setText(QStringLiteral("superlative 0")); + text.setPreGrade(KV_LEV7_GRADE); + translation0->setSuperlativeForm(text); + + + expression->setTranslation(1, QStringLiteral("translation 1")); + KEduVocTranslation *translation1 = expression->translation(1); + + translation1->setArticle(KEduVocText()); + + KEduVocConjugation conjugation1; + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), + KEduVocWordFlag::Singular | KEduVocWordFlag::First); + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), + KEduVocWordFlag::Singular | KEduVocWordFlag::Second); + conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), + KEduVocWordFlag::Singular | KEduVocWordFlag::Third + | KEduVocWordFlag::Neuter); + + translation1->setConjugation(QStringLiteral("tense"), conjugation1); + translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1"))); + translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1"))); + + return expression; +} + + +TestEntry *TestEntryTest::makeTestEntry(KEduVocExpression *expression) +{ + TestEntry *testEntry = new TestEntry(expression); + testEntry->setLanguageTo(0); + testEntry->setLanguageFrom(1); + testEntry->setConjugationTense(QStringLiteral("tense")); + testEntry->setConjugationPronouns({ + KEduVocWordFlag::Singular | KEduVocWordFlag::First, + KEduVocWordFlag::Singular | KEduVocWordFlag::Second, + KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter + }); + + return testEntry; +} + + +void TestEntryTest::cleanupTestCase() +{ + delete m_gradeTestEntry; + delete m_gradeExpression; + delete m_preGradeTestEntry; + delete m_preGradeExpression; +} + + +void TestEntryTest::test_practiceModeDependentMinGrade_written() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), + static_cast(KV_LEV1_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinGrade_gender() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), + static_cast(KV_LEV2_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinGrade_conjugation() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), + static_cast(KV_LEV3_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinGrade_comparsion() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), + static_cast(KV_LEV6_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxGrade_written() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), + static_cast(KV_LEV1_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxGrade_gender() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), + static_cast(KV_LEV2_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxGrade_conjugation() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), + static_cast(KV_LEV5_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxGrade_comparsion() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); + QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), + static_cast(KV_LEV7_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinPreGrade_written() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), + static_cast(KV_LEV1_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinPreGrade_gender() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), + static_cast(KV_LEV2_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinPreGrade_conjugation() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), + static_cast(KV_LEV3_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMinPreGrade_comparsion() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), + static_cast(KV_LEV6_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxPreGrade_written() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), + static_cast(KV_LEV1_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxPreGrade_gender() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), + static_cast(KV_LEV2_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxPreGrade_conjugation() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), + static_cast(KV_LEV5_GRADE)); +} + + +void TestEntryTest::test_practiceModeDependentMaxPreGrade_comparsion() +{ + Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); + QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), + static_cast(KV_LEV7_GRADE)); +} + +} + +QTEST_MAIN(TestEntryTests::TestEntryTest) diff --git a/src/collection/entryfilter.cpp b/src/collection/entryfilter.cpp --- a/src/collection/entryfilter.cpp +++ b/src/collection/entryfilter.cpp @@ -60,7 +60,7 @@ DocumentSettings documentSettings(m_doc->url().url() + QString::number(m_toTranslation)); documentSettings.load(); m_tenses = documentSettings.conjugationTenses(); - qDebug() << "Tenses" << m_tenses; +// qDebug() << "Tenses" << m_tenses; } } /* @@ -545,7 +545,7 @@ QList< TestEntry* > EntryFilter::conjugationTestEntries(bool ignoreBlocked) const { - qDebug() << "Filtering conjugation entries for tenses... " << m_tenses; +// qDebug() << "Filtering conjugation entries for tenses... " << m_tenses; // TODO CM make this configurable enum MODE { diff --git a/src/collection/testentry.h b/src/collection/testentry.h --- a/src/collection/testentry.h +++ b/src/collection/testentry.h @@ -15,6 +15,8 @@ #ifndef TESTENTRY_H #define TESTENTRY_H +#include + #include #include @@ -94,6 +96,15 @@ KEduVocExpression *entry() const; + grade_t practiceModeDependentMinGrade() const; + grade_t practiceModeDependentMinPreGrade() const; + grade_t practiceModeDependentMaxGrade() const; + grade_t practiceModeDependentMaxPreGrade() const; + +private: + grade_t practiceModeDependentGrade(std::function gradeFunc, + std::function minMaxFunc) const; + private: /// the entry itself KEduVocExpression *m_entry; diff --git a/src/collection/testentry.cpp b/src/collection/testentry.cpp --- a/src/collection/testentry.cpp +++ b/src/collection/testentry.cpp @@ -163,3 +163,70 @@ { m_conjugationPronouns = flags; } + +grade_t TestEntry::practiceModeDependentMinGrade() const +{ + return practiceModeDependentGrade(&KEduVocTranslation::grade, qMin); +} + + +grade_t TestEntry::practiceModeDependentMinPreGrade() const +{ + return practiceModeDependentGrade(&KEduVocText::preGrade, qMin); +} + + +grade_t TestEntry::practiceModeDependentMaxGrade() const +{ + return practiceModeDependentGrade(&KEduVocText::grade, qMax); +} + + +grade_t TestEntry::practiceModeDependentMaxPreGrade() const +{ + return practiceModeDependentGrade(&KEduVocText::preGrade, qMax); +} + + +grade_t TestEntry::practiceModeDependentGrade(std::function gradeFunc, + std::function minMaxFunc) const +{ + grade_t result(0); + const KEduVocTranslation *translation(entry()->translation(languageTo())); + switch (Prefs::practiceMode()) { + + // For gender practice the article (pre-)grades are required. + case Prefs::EnumPracticeMode::GenderPractice: + result = gradeFunc(translation->article()); + break; + + // For conjugation practice the conjugation (pre-)grades are required. + // For the specified tense the highest/lowest values of all specified gramatical persons + // is evaluated. + case Prefs::EnumPracticeMode::ConjugationPractice: + { + KEduVocConjugation conj(translation->getConjugation(conjugationTense())); + // Depending on what minMaxFunc is used result needs an appropriate initialisation + result = (minMaxFunc(0, 1) == 1) ? KV_MIN_GRADE:KV_MAX_GRADE; + foreach(KEduVocWordFlags pronoun, conjugationPronouns()) { + result = minMaxFunc(result, gradeFunc(conj.conjugation(pronoun))); + } + } + break; + + // For comparison practice the (pre-)grades of the positive, comparative and superlative + // are required. Then highest/lowest value is evaluated. + case Prefs::EnumPracticeMode::ComparisonPractice: + { + result = gradeFunc(translation->comparativeForm()); + result = minMaxFunc(result, gradeFunc(translation->superlativeForm())); + } + break; + + // For all other practice forms the basic (pre-)grades are required. + default: + result = gradeFunc(*translation); + break; + } + return result; +} diff --git a/src/practice/sessionmanagerbase.cpp b/src/practice/sessionmanagerbase.cpp --- a/src/practice/sessionmanagerbase.cpp +++ b/src/practice/sessionmanagerbase.cpp @@ -78,19 +78,19 @@ m_learningLanguageIndex = Prefs::learningLanguage(); m_knownLanguageIndex = Prefs::knownLanguage(); - qDebug() << "Practice: learning language:" << m_doc->identifier(m_learningLanguageIndex).name() - << " known language:" << m_doc->identifier(m_knownLanguageIndex).name(); +// qDebug() << "Practice: learning language:" << m_doc->identifier(m_learningLanguageIndex).name() +// << " known language:" << m_doc->identifier(m_knownLanguageIndex).name(); // Create the list of available entries for this training session. EntryFilter filter(m_doc, m_parent); m_allTestEntries = filter.entries(); - qDebug() << "Entries: ----------------"; - qDebug() << "Found " << m_allTestEntries.count() << " entries after filtering."; - foreach (TestEntry *entry, m_allTestEntries) { - qDebug() << "Entry: " << entry->languageFrom() << entry->entry()->translation(entry->languageFrom())->text() - << "to" << entry->languageTo() << entry->entry()->translation(entry->languageTo())->text(); - } +// qDebug() << "Entries: ----------------"; +// qDebug() << "Found " << m_allTestEntries.count() << " entries after filtering."; +// foreach (TestEntry *entry, m_allTestEntries) { +// qDebug() << "Entry: " << entry->languageFrom() << entry->entry()->translation(entry->languageFrom())->text() +// << "to" << entry->languageTo() << entry->entry()->translation(entry->languageTo())->text(); +// } // Create the list actual entries in this training session. This // is a pure virtual function and must be implemented by the diff --git a/src/practice/sessionmanagerfixed.cpp b/src/practice/sessionmanagerfixed.cpp --- a/src/practice/sessionmanagerfixed.cpp +++ b/src/practice/sessionmanagerfixed.cpp @@ -53,8 +53,8 @@ && m_currentEntries.count() < MaxEntries) { TestEntry *it = m_allTestEntries.at(i); - if (it->entry()->translation(it->languageTo())->grade() == 0 - && it->entry()->translation(it->languageTo())->preGrade() == 0) { + if (it->practiceModeDependentMinGrade() == 0 + && it->practiceModeDependentMinPreGrade() == 0) { m_currentEntries.append(it); numNewWords++; } @@ -72,7 +72,7 @@ // Step through all entries and collect those at the current // grade until the session is filled. foreach (TestEntry *entry, m_allTestEntries) { - if (entry->entry()->translation(entry->languageTo())->grade() == grade) { + if (entry->practiceModeDependentMaxGrade() == grade) { m_currentEntries.append(entry); } if (m_currentEntries.count() >= MaxEntries) { @@ -92,7 +92,7 @@ // Step through all entries and collect those at the current // grade until the session is filled. foreach (TestEntry *entry, m_allTestEntries) { - if (entry->entry()->translation(entry->languageTo())->preGrade() == preGrade) { + if (entry->practiceModeDependentMaxPreGrade() == preGrade) { m_currentEntries.append(entry); } if (m_currentEntries.count() >= MaxEntries) {