|
| 1 | +#include <QTest> |
| 2 | +#include <QList> |
| 3 | +#include <QDebug> |
| 4 | +#include "test_runner.h" |
| 5 | +#include "container.h" |
| 6 | + |
| 7 | +#define POINT(test_name, point) qInfo("TMC:"#test_name"."#point) |
| 8 | + |
| 9 | +test_runner::test_runner(QObject *parent) |
| 10 | + : QObject(parent) |
| 11 | +{ |
| 12 | + class Container; |
| 13 | + |
| 14 | +} |
| 15 | + |
| 16 | +void test_runner::list_modified_correctly() |
| 17 | +{ |
| 18 | + Container test_useful; |
| 19 | + POINT(list_modified_correctly, 3.1); |
| 20 | + |
| 21 | + QList<int> list; |
| 22 | + QList<int> correctList; |
| 23 | + for (int i = 0; i < 1000; i++) { |
| 24 | + list.append(i); |
| 25 | + if (i % 5 == 0) { |
| 26 | + correctList.append(i*3); |
| 27 | + } else { |
| 28 | + correctList.append(i); |
| 29 | + } |
| 30 | + } |
| 31 | + list = test_useful.listPractise(list); |
| 32 | + for (int i = 0; i < 1000; i++) { |
| 33 | + QVERIFY(list[i] == correctList[i]); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +void test_runner::correct_heights_returned() |
| 38 | +{ |
| 39 | + Container test_useful; |
| 40 | + POINT(correct_heights_returned, 3.2); |
| 41 | + QMap<QString, float> map; |
| 42 | + map.insert("Mark", 1.82f); |
| 43 | + map.insert("Anton", 1.90f); |
| 44 | + map.insert("Liisa", 1.59f); |
| 45 | + map.insert("Anna", 1.64f); |
| 46 | + QList<float> correctHeights; |
| 47 | + correctHeights.append(1.64f); |
| 48 | + correctHeights.append(1.90f); |
| 49 | + QList<float> returned = test_useful.heights(map); |
| 50 | + QVERIFY(correctHeights.size() == returned.size()); |
| 51 | + for (int i = 0; i < returned.size(); i++) |
| 52 | + QVERIFY(qFuzzyCompare(returned[i], correctHeights[i])); |
| 53 | +} |
| 54 | + |
| 55 | +void test_runner::correct_names_returned() |
| 56 | +{ |
| 57 | + Container test_useful; |
| 58 | + POINT(correct_names_returned, 3.3); |
| 59 | + QMap<QString, float> map; |
| 60 | + map.insert("Mark", 1.82f); |
| 61 | + map.insert("Anton", 1.90f); |
| 62 | + map.insert("Liisa", 1.59f); |
| 63 | + map.insert("Anna", 1.64f); |
| 64 | + QList<QString> correctNames; |
| 65 | + correctNames.append("Anton"); |
| 66 | + correctNames.append("Mark"); |
| 67 | + QList<QString> returned = test_useful.names(map); |
| 68 | + QVERIFY(correctNames.size() == returned.size()); |
| 69 | + for (int i = 0; i < returned.size(); i++) { |
| 70 | + QVERIFY(returned[i] == correctNames[i]); |
| 71 | + } |
| 72 | +} |
0 commit comments