summaryrefslogtreecommitdiff
path: root/tests/unit/Card/Card_GenerateAnswers_test.cpp
blob: f381dafad015de446c65d6ec121f930303caad95 (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
#include "Card_GenerateAnswers_test.h"

#include <initializer_list>

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

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

void GenerateAnswersTest::TearDown()
{
    for(Field* field: fields)
        delete field;
}

TEST_P(GenerateAnswersTest, generateAnswers)
    {
    auto param = GetParam();
    dict.addRecords(param.records);
    for(int i: param.packFields)
        addFieldToPack(i);

    unsigned i = 0;
    for(vector<string> expectedCardFields: param.answers)
    {
        SCOPED_TRACE(i);
        Card card(&pack, expectedCardFields[0].c_str());
        for(unsigned j = 1; j < expectedCardFields.size(); j++)
        {
            SCOPED_TRACE(j);
            ASSERT_EQ_QSTR(QString(expectedCardFields[j].c_str()),
                card.getAnswers()[j - 1]);
        }
        i++;
    }
}

TEST_F(GenerateAnswersTest, dropAnswers)
    {
    const vector<string> fieldValues {"table", "стол"};

    DicRecord* record = new DicRecord;
    dict.addRecord(record);
    for(unsigned i = 0; i < fieldValues.size(); i++)
    {
        addFieldToPack(i);
        record->setField(RecordsParam::fieldNames[i].c_str(), fieldValues[i].c_str());
    }
    Card card(&pack, fieldValues[0].c_str());

    ASSERT_EQ(QString(fieldValues[1].c_str()), card.getAnswers().first());

    record->setField("Russian", "кровать");
    ASSERT_EQ(QString("кровать"), card.getAnswers().first());
}

void GenerateAnswersTest::addFieldToPack(unsigned fieldId)
{
    Field* field = new Field(RecordsParam::fieldNames[fieldId].c_str(), "Normal");
    fields.push_back(field);
    pack.addField(field);
}