extquotes test improvement

This commit is contained in:
Evgenii Alekseev 2017-02-15 00:43:21 +03:00
parent 9c8dbdcb41
commit 1841fb5ed2

View File

@ -57,17 +57,11 @@ void TestExtQuotes::test_run()
// check values // check values
QVERIFY(spy.wait(5000)); QVERIFY(spy.wait(5000));
QList<QVariant> arguments = spy.takeFirst(); QList<QVariant> arguments = spy.takeFirst();
cache[QString("ask")] for (auto &type : types)
= arguments.at(0).toHash()[extQuotes->tag(QString("ask"))]; cache[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
cache[QString("bid")]
= arguments.at(0).toHash()[extQuotes->tag(QString("bid"))];
cache[QString("price")]
= arguments.at(0).toHash()[extQuotes->tag(QString("price"))];
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) { for (auto type : types) {
QCOMPARE(firstValue[extQuotes->tag(type)].toDouble(), 0.0);
QVERIFY((cache[type].toDouble() > price.first) QVERIFY((cache[type].toDouble() > price.first)
&& (cache[type].toDouble() < price.second)); && (cache[type].toDouble() < price.second));
} }
@ -84,24 +78,14 @@ void TestExtQuotes::test_derivatives()
QVERIFY(spy.wait(5000)); QVERIFY(spy.wait(5000));
QList<QVariant> arguments = spy.takeFirst(); QList<QVariant> arguments = spy.takeFirst();
QVariantHash values; QVariantHash values;
values[QString("ask")] for (auto type : types)
= arguments.at(0).toHash()[extQuotes->tag(QString("ask"))]; values[type] = arguments.at(0).toHash()[extQuotes->tag(type)];
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) { for (auto type : types) {
QCOMPARE(arguments.at(0) QCOMPARE(arguments.at(0)
.toHash()[extQuotes->tag(QString("%1chg").arg(type))] .toHash()[extQuotes->tag(QString("%1chg").arg(type))]
.toDouble(), .toDouble(),
(values[type].toDouble() - cache[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());
} }
} }