From 1841fb5ed22555c3d68db2f7738a860ba5498681 Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Wed, 15 Feb 2017 00:43:21 +0300 Subject: [PATCH] extquotes test improvement --- sources/test/testextquotes.cpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/sources/test/testextquotes.cpp b/sources/test/testextquotes.cpp index 288bb28..5f5d48f 100644 --- a/sources/test/testextquotes.cpp +++ b/sources/test/testextquotes.cpp @@ -57,17 +57,11 @@ void TestExtQuotes::test_run() // check values QVERIFY(spy.wait(5000)); QList arguments = spy.takeFirst(); - cache[QString("ask")] - = arguments.at(0).toHash()[extQuotes->tag(QString("ask"))]; - cache[QString("bid")] - = arguments.at(0).toHash()[extQuotes->tag(QString("bid"))]; - cache[QString("price")] - = arguments.at(0).toHash()[extQuotes->tag(QString("price"))]; + for (auto &type : types) + cache[type] = arguments.at(0).toHash()[extQuotes->tag(type)]; - QCOMPARE(firstValue[extQuotes->tag(QString("ask"))].toDouble(), 0.0); - QCOMPARE(firstValue[extQuotes->tag(QString("bid"))].toDouble(), 0.0); - QCOMPARE(firstValue[extQuotes->tag(QString("price"))].toDouble(), 0.0); for (auto type : types) { + QCOMPARE(firstValue[extQuotes->tag(type)].toDouble(), 0.0); QVERIFY((cache[type].toDouble() > price.first) && (cache[type].toDouble() < price.second)); } @@ -84,24 +78,14 @@ void TestExtQuotes::test_derivatives() QVERIFY(spy.wait(5000)); QList arguments = spy.takeFirst(); QVariantHash values; - values[QString("ask")] - = arguments.at(0).toHash()[extQuotes->tag(QString("ask"))]; - values[QString("bid")] - = arguments.at(0).toHash()[extQuotes->tag(QString("bid"))]; - values[QString("price")] - = arguments.at(0).toHash()[extQuotes->tag(QString("price"))]; + for (auto type : types) + values[type] = arguments.at(0).toHash()[extQuotes->tag(type)]; for (auto type : types) { QCOMPARE(arguments.at(0) .toHash()[extQuotes->tag(QString("%1chg").arg(type))] .toDouble(), (values[type].toDouble() - cache[type].toDouble())); - QWARN("Possible round error"); - QCOMPARE(arguments.at(0) - .toHash()[extQuotes->tag(QString("perc%1chg").arg(type))] - .toDouble(), - 100.0 * (values[type].toDouble() - cache[type].toDouble()) - / values[type].toDouble()); } }