add tests for project
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest>
|
||||
|
||||
#include "data/campdata.h"
|
||||
#include "data/serviceitem.h"
|
||||
#include "data/addressitem.h"
|
||||
#include "data/personprice.h"
|
||||
|
||||
class CampTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void campDataDefaultsAreZeroed()
|
||||
{
|
||||
CampData camp;
|
||||
|
||||
QCOMPARE(camp.totalPrice().toDouble(), 0.0);
|
||||
QCOMPARE(camp.sale().toDouble(), 0.0);
|
||||
QCOMPARE(camp.totalSale().toDouble(), 0.0);
|
||||
QCOMPARE(camp.fullPrice().toDouble(), 0.0);
|
||||
QVERIFY(!camp.fixedSale());
|
||||
QVERIFY(!camp.onVoucher());
|
||||
}
|
||||
|
||||
void campPricesRoundTripWithoutLoss()
|
||||
{
|
||||
CampData camp;
|
||||
|
||||
camp.setTotalPrice(QDecDouble(19.9));
|
||||
camp.setSale(QDecDouble(4.9));
|
||||
camp.setFullPrice(QDecDouble(24.8));
|
||||
|
||||
QVERIFY(qAbs(camp.totalPrice().toDouble() - 19.9) < 0.0001);
|
||||
QVERIFY(qAbs(camp.sale().toDouble() - 4.9) < 0.0001);
|
||||
QVERIFY(qAbs(camp.fullPrice().toDouble() - 24.8) < 0.0001);
|
||||
}
|
||||
|
||||
void campCollectsPeopleAndServices()
|
||||
{
|
||||
CampData camp;
|
||||
auto person = QSharedPointer<AddressItem>::create();
|
||||
auto service = QSharedPointer<ServiceItem>::create();
|
||||
|
||||
camp.addPerson(person);
|
||||
camp.addServiceItem(service);
|
||||
QCOMPARE(camp.people().size(), 1);
|
||||
QCOMPARE(camp.services().size(), 1);
|
||||
|
||||
camp.removePerson(person);
|
||||
camp.removeServiceItem(service);
|
||||
QVERIFY(camp.people().isEmpty());
|
||||
QVERIFY(camp.services().isEmpty());
|
||||
}
|
||||
|
||||
void serviceItemPricesRoundTrip()
|
||||
{
|
||||
ServiceItem item;
|
||||
|
||||
item.setPrice(QDecDouble(33.3));
|
||||
item.setTotalPrice(QDecDouble(66.6));
|
||||
item.setSale(QDecDouble(3.3));
|
||||
|
||||
QVERIFY(qAbs(item.price().toDouble() - 33.3) < 0.0001);
|
||||
QVERIFY(qAbs(item.totalPrice().toDouble() - 66.6) < 0.0001);
|
||||
QVERIFY(qAbs(item.sale().toDouble() - 3.3) < 0.0001);
|
||||
}
|
||||
|
||||
void addressItemOwnerFlagAndPrice()
|
||||
{
|
||||
AddressItem person;
|
||||
|
||||
person.setOwner(true);
|
||||
person.setPrice(QDecDouble(12.5));
|
||||
|
||||
QVERIFY(person.owner());
|
||||
QVERIFY(qAbs(person.price().toDouble() - 12.5) < 0.0001);
|
||||
}
|
||||
|
||||
void personPriceAgeRangeAndPrice()
|
||||
{
|
||||
PersonPrice price;
|
||||
|
||||
price.setFromAge(3);
|
||||
price.setToAge(12);
|
||||
price.setPrice(QDecDouble(7.5));
|
||||
price.setActive(true);
|
||||
|
||||
QCOMPARE(price.fromAge(), 3);
|
||||
QCOMPARE(price.toAge(), 12);
|
||||
QVERIFY(qAbs(price.price().toDouble() - 7.5) < 0.0001);
|
||||
QVERIFY(price.active());
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
CampTests tests;
|
||||
return QTest::qExec(&tests, argc, argv);
|
||||
}
|
||||
|
||||
#include "camp_tests.moc"
|
||||
Reference in New Issue
Block a user