58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
#include <QCoreApplication>
|
|
#include <QtTest>
|
|
|
|
#include "data/voucher.h"
|
|
|
|
class ShopTests : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void defaultsMatchNewVoucherState()
|
|
{
|
|
Voucher voucher;
|
|
|
|
QCOMPARE(voucher.totalPrice().toDouble(), 0.0);
|
|
QCOMPARE(voucher.status(), Voucher::NEW);
|
|
QCOMPARE(voucher.eetStatus(), Voucher::EET_FOR_SEND);
|
|
}
|
|
|
|
void totalPriceRoundTripUsesFixedPointStorage()
|
|
{
|
|
Voucher voucher;
|
|
|
|
voucher.setTotalPrice(QDecDouble(19.9));
|
|
|
|
QVERIFY(qAbs(voucher.totalPrice().toDouble() - 19.9) < 0.0001);
|
|
}
|
|
|
|
void vatAmountIsDifferenceBetweenTotalAndBase()
|
|
{
|
|
Voucher voucher;
|
|
|
|
voucher.setTotalPriceVatHigh(QDecDouble(121));
|
|
voucher.setPriceVatHigh(QDecDouble(100));
|
|
|
|
QVERIFY(qAbs(voucher.vatAmountHigh().toDouble() - 21.0) < 0.0001);
|
|
}
|
|
|
|
void voucherSumAccumulatesPricesWithoutTruncation()
|
|
{
|
|
VoucherSum sum(0, 0);
|
|
|
|
sum.addPrice(QDecDouble(19.9));
|
|
sum.addPrice(QDecDouble(0.1));
|
|
|
|
QVERIFY(qAbs(sum.totalPrice().toDouble() - 20.0) < 0.0001);
|
|
}
|
|
};
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QCoreApplication app(argc, argv);
|
|
ShopTests tests;
|
|
return QTest::qExec(&tests, argc, argv);
|
|
}
|
|
|
|
#include "shop_tests.moc"
|