Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleverca22/b66811dc595363b85425 to your computer and use it in GitHub Desktop.
Save cleverca22/b66811dc595363b85425 to your computer and use it in GitHub Desktop.
conversion problem
********* 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 *********
#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);
}
#include <QtTest/QtTest>
class TestCase : public QObject {
Q_OBJECT
private slots:
void convert_data();
void convert();
};
######################################################################
# 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