Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <QtTest>
- #include "markettask.h"
- using namespace std;
- class LabUnitTests : public QObject
- {
- Q_OBJECT
- public:
- LabUnitTests()
- {
- testcasefile.open("test_input.txt");
- ethalon.open("test_ethalon.txt");
- if (!testcasefile.is_open() || !ethalon.is_open())
- qDebug() << "Files doesn't open";
- }
- ~LabUnitTests()
- {
- testcasefile.close();
- ethalon.close();
- }
- private slots:
- void test_border_data()
- {
- initTestCase("border", 3);
- }
- void test_border()
- {
- QFETCH(int, n);
- QFETCH(int, k);
- QFETCH(long long, result);
- QCOMPARE(stepsToMarket(n, k), result);
- }
- void test_ordinary_data()
- {
- initTestCase("ordinary", 1);
- }
- void test_ordinary()
- {
- QFETCH(int, n);
- QFETCH(int, k);
- QFETCH(long long, result);
- QCOMPARE(stepsToMarket(n, k), result);
- }
- void test_invalid_input_data()
- {
- initTestCase("invalid", 6);
- }
- void test_invalid_input()
- {
- QFETCH(int, n);
- QFETCH(int, k);
- QFETCH(long long, result);
- QCOMPARE(stepsToMarket(n, k), result);
- }
- private:
- void initTestCase(string name, int count)
- {
- string prefix = name + "_";
- QTest::addColumn<int>("n");
- QTest::addColumn<int>("k");
- QTest::addColumn<long long>("result");
- int n, k;
- long long res;
- for (int i = 0; i < count; i++) {
- testcasefile >> n >> k >> res;
- string rowName = prefix + to_string(i + 1);
- QTest::newRow(rowName.c_str()) << n << k << res;
- }
- }
- ifstream testcasefile;
- ifstream ethalon;
- };
- QTEST_APPLESS_MAIN(LabUnitTests)
- #include "tst_labunittests.moc"
Add Comment
Please, Sign In to add comment