This repository has been archived on 2021-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
FractionTask/tst_fractiontest.cpp

67 lines
1.1 KiB
C++
Raw Normal View History

2021-09-17 12:32:14 +02:00
#include <QtTest>
#include "fraction.hpp"
class FractionTest : public QObject
{
Q_OBJECT
public:
FractionTest();
~FractionTest();
private slots:
void test_constructor();
void test_equivalence();
};
FractionTest::FractionTest()
{
}
FractionTest::~FractionTest()
{
}
void FractionTest::test_constructor()
{
Fraction f1 = Fraction(1, 2);
QVERIFY(f1 == 0.5f);
QVERIFY(f1 == 0.5);
QVERIFY(f1.numerator() == 1);
QVERIFY(f1.denominator() == 2);
Fraction f2 = Fraction(2,4);
QVERIFY(f1 == f2);
QVERIFY(f2 == 0.5f);
QVERIFY(f2 == 0.5);
QVERIFY(f2.numerator() == 1);
QVERIFY(f2.denominator() == 2);
}
void FractionTest::test_equivalence()
{
Fraction f1 = Fraction(1, 1);
Fraction f2 = Fraction(1, 1);
QVERIFY(f1 == f2);
QVERIFY(f1 == 1);
QVERIFY(f1 == 1.0);
QVERIFY(f1 == 1.0f);
QVERIFY(f2 == 1);
QVERIFY(f2 == 1.0);
QVERIFY(f2 == 1.0f);
Fraction f3 = Fraction(2, 3);
QVERIFY(f3 != 1);
QVERIFY(f3 != 1.0);
QVERIFY(f3 != 1.0f);
}
QTEST_APPLESS_MAIN(FractionTest)
#include "tst_fractiontest.moc"