summaryrefslogtreecommitdiff
path: root/tests/unit/Card/Card_GenerateAnswers_test.cpp
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
committerJedidiah Barber <contact@jedbarber.id.au>2021-07-14 11:49:10 +1200
commitd24f813f3f2a05c112e803e4256b53535895fc98 (patch)
tree601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /tests/unit/Card/Card_GenerateAnswers_test.cpp
Initial mirror commitHEADmaster
Diffstat (limited to 'tests/unit/Card/Card_GenerateAnswers_test.cpp')
-rw-r--r--tests/unit/Card/Card_GenerateAnswers_test.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/unit/Card/Card_GenerateAnswers_test.cpp b/tests/unit/Card/Card_GenerateAnswers_test.cpp
new file mode 100644
index 0000000..f381daf
--- /dev/null
+++ b/tests/unit/Card/Card_GenerateAnswers_test.cpp
@@ -0,0 +1,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);
+}