summaryrefslogtreecommitdiff
path: root/tests/unit/CardPack/CardPack_GenerateCards_test.cpp
blob: c7e7fcbd1a81b8308aa99e5408cc449df688a1d7 (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
#include "CardPack_GenerateCards_test.h"

#include <initializer_list>

#include "../../common/printQtTypes.h"
#include "../../../src/dictionary/IDictionary.h"
#include "../../../src/dictionary/Field.h"
#include "../../../src/dictionary/DicRecord.h"

vector<Field*> GenerateCardsTest::fields;

INSTANTIATE_TEST_CASE_P(, GenerateCardsTest,
    testing::ValuesIn(RecordsParam::createParams()) );

vector<Field*> GenerateCardsTest::getFields()
{
    static vector<string> names {"English", "Russian"};
    if(fields.empty())
        for(string name: names)
            fields.push_back(new Field(name.c_str(), "Normal"));
    return fields;
}

void GenerateCardsTest::TearDownTestCase()
{
    for(Field* field: fields)
        delete field;
}

TEST_P(GenerateCardsTest, generateQuestions)
    {
    auto param = GetParam();
    dict.addRecords(param.records);
    for(int fieldId: param.packFields)
        pack.addField(getFields()[ fieldId ]);
    pack.generateQuestions();

    QStringList questions;
    for(string question: param.questions)
        questions << question.c_str();

    ASSERT_EQ(questions, pack.getCardQuestions());
}