From 7492e37e021fcb3d5f8507c44e9cea10bd66f96d Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Thu, 6 Jun 2024 14:01:01 +0200 Subject: [PATCH] Finished test for Neuhauser/Stockerau/748 --- main/main.cpp | 134 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 13 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index a63f691..62534bf 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -218,20 +218,128 @@ int main() { //QDateTime s(QDate(2024, 5, 29), QTime()); // wednesday //QDateTime s(QDate(2024, 5, 30), QTime()); // thursday - QDateTime s(QDate(2024, 5, 31), QTime()); // friday - QDateTime end; - QDateTime start = s.addSecs(7*60*60); - CalcState cs; - for (int i = 600; i <= 600; i += 10) { - // for (int i = 70; i <= 70; i += 10) { - double cost = i; - if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value - qCritical() << "start" << start.toString(Qt::ISODate); - qCritical() << " cost" << cost; - qCritical() << " end" << end.toString(Qt::ISODate) << endl; - } else { - qCritical() << "ERROR CalcState" << cs.toString(); + double const x = 30.0/7.0; + double cost; + int durationInMinutes; + int offsetInMinutes = 0; + + for (int day = Qt::Monday; day <= Qt::Sunday; ++day) { + QDateTime s(QDate(2024, 5, 19 + day), QTime()); // 20: (whit) monday,..., 26: sunday + QDateTime end; + + for (int minutes = 0; minutes < 1440; ++minutes) { + //for (int minutes = 0; minutes < 1440; ++minutes) { + QDateTime start = s.addSecs(minutes * 60); + QDateTime effectiveStart = start; + + if (day >= Qt::Monday && day <= Qt::Friday) { + if (start.time() < QTime(8,0,0)) { + effectiveStart.setTime(QTime(8,0,0)); + } else + if (start.time() <= QTime(12,0,0)) { + effectiveStart = start; + } else + if (start.time() < QTime(13,30,0)) { + effectiveStart.setTime(QTime(13,30,0)); + } else + if (start.time() <= QTime(18,0,0)) { + effectiveStart = start; + } else { + effectiveStart = start.addDays(1); + effectiveStart.setTime(QTime(8,0,0)); // saturday + } + } else + if (day == Qt::Saturday) { + if (start.time() < QTime(8,0,0)) { + effectiveStart.setTime(QTime(8,0,0)); + } else + if (start.time() <= QTime(12,0,0)) { + effectiveStart = start; + } else { + effectiveStart = start.addDays(2); + effectiveStart.setTime(QTime(8,0,0)); // monday + } + } else + if (day == Qt::Sunday) { + effectiveStart = start.addDays(1); + effectiveStart.setTime(QTime(8,0,0)); // monday + } + + for (int i = 70; i <= 600; i += 10) { + // for (int i = 70; i <= 70; i += 10) { + cost = i; + if ((cs = compute_duration_for_parking_ticket(&cfg, start, cost, end))) { // return value + durationInMinutes = truncf(x * (i/10)); + offsetInMinutes = 0; + if (day >= Qt::Monday && day <= Qt::Friday) { + if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(12, 0, 0)) { + if (effectiveStart.date().dayOfWeek() == start.date().dayOfWeek()) { + if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(12, 0, 0)) { + offsetInMinutes = 90; // 12:00 - 13:30 + } + } else { + offsetInMinutes = 14 * 60; // 18:00 -> next day, 8:00 + if (effectiveStart.time().addSecs(durationInMinutes * 60) <= QTime(12, 0, 0)) { + offsetInMinutes = 0; + } else { + if (effectiveStart.date().dayOfWeek() == Qt::Saturday) { + offsetInMinutes = (12 + 24 + 8) * 60; + } else { + offsetInMinutes = 90; + } + } + } + } else + if (effectiveStart.time() >= QTime(13, 30, 0)) { + if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(18, 0, 0)) { + offsetInMinutes = 14 * 60; // 18:00 -> next day, 8:00 + } + } + } else + if (day == Qt::Saturday) { + if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(12, 0, 0)) { + if (effectiveStart.date().dayOfWeek() == start.date().dayOfWeek()) { + if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(12, 0, 0)) { + offsetInMinutes = (12 + 24 + 8) * 60; // monday, 8:00 + } + } else { + offsetInMinutes = (12 + 24 + 8) * 60; // monday, 8:00 + if (effectiveStart.time().addSecs(durationInMinutes * 60) <= QTime(12, 0, 0)) { + offsetInMinutes = 0; + } else { + offsetInMinutes = 90; + } + } + } + } else + if (day == Qt::Sunday) { + if (effectiveStart.time() >= QTime(8, 0, 0) && effectiveStart.time() <= QTime(12, 0, 0)) { + if (effectiveStart.time().addSecs(durationInMinutes * 60) > QTime(12, 0, 0)) { + offsetInMinutes = 90; + } + } + } + + if ((durationInMinutes + offsetInMinutes) == (effectiveStart.secsTo(end) / 60)) { + continue; + } + } + + if (!cs) { + qCritical() << "ERROR CalcState" << cs.toString() << endl; + } else { + qCritical() << "SUCCESS"; + } + qCritical() << "start ............................" << start.toString(Qt::ISODate); + qCritical() << "effectiveStart ..................." << effectiveStart.toString(Qt::ISODate); + qCritical() << "cost ............................." << cost; + qCritical() << "durationMinutes .................." << durationInMinutes; + qCritical() << "offsetInMinutes .................." << offsetInMinutes; + qCritical() << "effectiveStart.secsTo(end) / 60 .." << effectiveStart.secsTo(end) / 60; + qCritical() << "end .............................." << end.toString(Qt::ISODate) << endl; + exit(-1); + } } } }