diff options
Diffstat (limited to 'tests/common/RecordsParam.cpp')
-rw-r--r-- | tests/common/RecordsParam.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/common/RecordsParam.cpp b/tests/common/RecordsParam.cpp new file mode 100644 index 0000000..74ad802 --- /dev/null +++ b/tests/common/RecordsParam.cpp @@ -0,0 +1,51 @@ +#include "RecordsParam.h" + +#include "../../src/dictionary/Field.h" +#include "../../src/dictionary/DicRecord.h" + +const vector<string> RecordsParam::fieldNames {"English", "Russian", "Finnish"}; + +RecordsParam::RecordsParam( + vector<int> packFields, + vector<vector<string> > records, + vector<string> questions, + vector<vector<string> > answers): + packFields(packFields), + questions(questions), + answers(answers) +{ + for(vector<string> fieldValues: records) + { + DicRecord* record = new DicRecord; + for(unsigned i = 0; i < fieldValues.size(); i++) + record->setField(fieldNames[i].c_str(), fieldValues[i].c_str()); + this->records << record; + } +} + +vector<string> RecordsParam::hashToStrVector(const QHash<QString, QString>& hash, + const vector<string>& keys) +{ + vector<string> res; + for(unsigned i = 0; i < keys.size(); i++) + res.push_back( hash[keys[i].c_str()].toStdString() ); + return res; +} + +vector<string> RecordsParam::recordsToStr() const +{ + vector<string> res; + for(DicRecord* record: records) + { + vector<string> fieldValues = hashToStrVector(record->getFields(), fieldNames); + res.push_back(string("(") + vectorToStr<string>(fieldValues) + ")"); + } + return res; +} + +ostream& operator<<(ostream& os, const RecordsParam& param) +{ + os << "Fields(" << param.vectorToStr<int>(param.packFields) << ") "; + os << "{" << param.vectorToStr<string>( param.recordsToStr() ) << "}"; + return os; +} |