add compact tariff tests

This commit is contained in:
2026-12-02 11:02:15 +01:00
parent 98be94f33b
commit c4ad676b86
9 changed files with 1288 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
QT = core
CONFIG += console c++17
CONFIG -= app_bundle
TEMPLATE = app
TARGET = postpaid_checks
INCLUDEPATH += ../../library/include
SOURCES += postpaid_checks.cpp
+50
View File
@@ -0,0 +1,50 @@
#include <mobilisis/compact_engine.h>
#include <QCoreApplication>
#include <QDebug>
#include <cstdlib>
static void check(bool ok, const QString &why) {
if (!ok) { qCritical().noquote() << why; std::exit(1); }
}
int main(int argc, char **argv) {
QCoreApplication app(argc, argv);
check(argc >= 2, "Usage: postpaid_checks tariff_start_to_now.json [exit ISO timestamp]");
Mobilisis::CompactEngine e;
check(e.load(QString::fromLocal8Bit(argv[1])), e.error);
const QDateTime start(QDate(2026,11,17), QTime(12,0), Qt::LocalTime);
Mobilisis::CompactChoice q;
qint64 paid = 0;
auto quote = [&](qint64 secs) {
check(e.quoteStay("SHORT_TERM_PARKING",start,start.addSecs(secs),q,paid),e.error);
check(q.end == start.addSecs(secs),"Billing end must not move");
};
e.postpaid["billingMode"] = "exact";
quote(0); check(q.price == 0,"Zero stay");
quote(60); check(q.price == 10,"One minute rounds up to ten cents");
quote(3600); check(q.price == 200,"Exact hour");
quote(3660); check(q.price == 210,"61 minutes exact");
quote(3601); check(q.price == 210,"Started minute");
e.postpaid["billingMode"] = "started_hours";
quote(3600); check(q.price == 200,"Exact hour must not become two");
quote(3601); check(q.price == 400,"One second beyond an hour");
e.postpaid["billingMode"] = "exact";
e.postpaid["exitGraceMinutes"] = 15;
quote(3600); check(q.price == 200,"Grace must not reduce charge");
check(!e.quoteStay("SHORT_TERM_PARKING",start,start.addSecs(-1),q,paid),"Reject future entry");
check(!e.quoteStay("UNKNOWN",start,start,q,paid),"Reject unknown product");
auto profile=e.tariff.profiles["all"];
profile["breaks"]=QJsonArray{QJsonObject{{"from","12:30"},{"to","13:00"}}};
e.tariff.profiles["all"]=profile;
quote(5400); check(paid==3600 && q.price==200,"Exclude lunch break");
profile["breaks"]=QJsonArray{}; e.tariff.profiles["all"]=profile;
quote(13*3600); check(paid==13*3600-60,"Respect configured 23:59 end across midnight");
check(!e.quoteStay("SHORT_TERM_PARKING",start,start.addDays(9),q,paid),"Reject uncovered long stay");
e.postpaid["moneyIncrementMinor"]=0;
check(!e.quoteStay("SHORT_TERM_PARKING",start,start,q,paid),"Reject invalid rounding");
e.postpaid["moneyIncrementMinor"]=10;
const auto end=argc>2 ? QDateTime::fromString(QString::fromLocal8Bit(argv[2]),Qt::ISODate)
: QDateTime::currentDateTime();
const QDateTime entry(end.date(),QTime(12,0),Qt::LocalTime);
check(e.quoteStay("SHORT_TERM_PARKING",entry,end,q,paid),e.error);
qInfo()<<"entry"<<entry<<"end"<<q.end<<"paidSeconds"<<paid<<"priceMinor"<<q.price;
qInfo()<<"Postpaid checks passed";
}