Last active
August 29, 2015 14:13
-
-
Save cleverca22/b66811dc595363b85425 to your computer and use it in GitHub Desktop.
conversion problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
********* Start testing of TestCase ********* | |
Config: Using QTest library 4.8.5, Qt 4.8.5 | |
PASS : TestCase::initTestCase() | |
QDEBUG : TestCase::convert(201) 201 | |
QDEBUG : TestCase::convert(201.6) 201.6 | |
PASS : TestCase::convert() | |
PASS : TestCase::cleanupTestCase() | |
Totals: 3 passed, 0 failed, 0 skipped | |
********* Finished testing of TestCase ********* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "test.h" | |
QTEST_MAIN(TestCase) | |
void TestCase::convert_data() { | |
QTest::addColumn<QString>("input"); | |
QTest::addColumn<int>("output"); | |
QTest::newRow("201") << "201" << 20100; | |
QTest::newRow("201.6") << "201.6" << 20160; | |
} | |
int parseValue(QString input) { | |
QStringList parts = input.split("."); | |
Q_ASSERT(parts.length() <= 2); | |
if (parts.length() == 1) { | |
return parts[0].toInt() * 100; | |
} else { | |
int first = parts[0].toInt() * 100; | |
Q_ASSERT(parts[1].length() <= 2); | |
if (parts[1].length() == 1) { | |
return first + (parts[1].toInt() * 10); | |
} else { | |
return first + parts[1].toInt(); | |
} | |
} | |
} | |
void TestCase::convert() { | |
QFETCH(QString,input); | |
QFETCH(int,output); | |
qDebug() << input.toDouble(); | |
int converted = parseValue(input); | |
QCOMPARE(output,converted); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtTest/QtTest> | |
class TestCase : public QObject { | |
Q_OBJECT | |
private slots: | |
void convert_data(); | |
void convert(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################### | |
# Automatically generated by qmake (2.01a) Wed Jan 14 11:32:13 2015 | |
###################################################################### | |
QT += testlib | |
TEMPLATE = app | |
TARGET = | |
DEPENDPATH += . | |
INCLUDEPATH += . | |
# Input | |
HEADERS += test.h | |
SOURCES += test.cpp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment