#include "../QtCalculator/calculator.h"
INCLUDEPATH += "../QtCalculator/calculator.h"SOURCES += tst_testqtcalculatortest.cpp ../QtCalculator/calculator.cpp
std::vector<int> v;CPPUNIT_ASSERT_THROW( v.at( 50 ), std::out_of_range );
void TestQtCalculatorTest::testCaseDiv_data(){ QTest::addColumn<double>("arg1"); QTest::addColumn<double>("arg2"); QTest::addColumn<double>("expected"); QTest::newRow("div") << 4.0 << 2.0 << 2.0; QTest::newRow("div") << -5.0 << 5.0 << -1.0; //QTest::newRow("div") << 0.0 << 0.0 << 0.0;}void TestQtCalculatorTest::testCaseDiv(){ QFETCH(double, arg1); QFETCH(double, arg2); QFETCH(double, expected); Calculator calc; double actual = calc.div(arg1, arg2); double delta = 0.0001; bool result = qFuzzyCompare(expected, actual, delta); QString message = QString("expected = %1; actual = %2; delta = %3;").arg(expected).arg(actual).arg(delta); QVERIFY2(result, message.toStdString().c_str());}
private: Ui::Dialog *ui;
double Calculator::div(double a, double b) throw(std::invalid_argument){ if (b != 0) { return a/b; } else { throw std::invalid_argument("Divide by zero"); }}
public: Ui::Dialog *ui;
C++ (Qt)try{ double actual = calc.div(arg1, arg2);}catch (std::invalid_argument e){ // обрабатываешь исключение}
C++ (Qt)class A{public: int a() const { return _a; }private: int _a;};
QTest::addColumn<double>("expected");