From 6b76c4c2dd11f494bf3ca63d3a2d3bc7714ef970 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 6 Dec 2023 10:52:35 +0100 Subject: [PATCH] Add test cases for neuhauser. --- main/main.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 6202a1f..35bb543 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -33,13 +33,66 @@ extern "C" char* strptime(const char* s, #include "calculator_functions.h" #include +#define SZEGED (1) +#define NEUHAUSER_KORNEUBURG (0) + int main() { - //std::ifstream input("/tmp/tariff_korneuburg.json"); +#if NEUHAUSER_KORNEUBURG==1 + std::ifstream input("/tmp/tariff_korneuburg.json"); int pop_max_time; + + std::stringstream sstr; + while(input >> sstr.rdbuf()); + std::string json(sstr.str()); + + Calculator calculator; + Configuration cfg; + + bool isParsed = cfg.ParseJson(&cfg, json.c_str()); + cout << endl; + + if (isParsed) { + { + pop_max_time = 3*60; + bool nextDay = false; + bool prePaid = true; + // zone 1 (lila) + QDateTime s(QDate(2023, 11, 30), QTime()); + QDateTime end; + for (int duration = 30; duration <= pop_max_time; duration += 5) { + for (int offset = 420; offset < 1140; ++offset) { + if (offset > 720 && offset < 840) { + continue; + } + QDateTime start = s.addSecs(offset * 60); + //qCritical() << "start" << start.toString(Qt::ISODate); + + double cost = calculator.GetCostFromDuration(&cfg, 3, start, end, duration, nextDay, prePaid); + //Q_ASSERT(cost == duration*2.5); + //qCritical() << ""; + //qCritical() << "start" << start.toString(Qt::ISODate) + // << "end" << end.toString(Qt::ISODate) + // << "duration" << duration + // << "cost" << cost; + + std::string duration = calculator.GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost); + //Q_ASSERT(cost == duration*2.5); + qCritical() << "start" << start.toString(Qt::ISODate) + << "cost" << cost + << "until" << duration.c_str() << start.secsTo(QDateTime::fromString(duration.c_str(), Qt::ISODate)) / 60; + } + } + } + } + return 0; + +#elif SZEGED==1 std::ifstream input; - for (int t=1; t < 7; t+=20) { + int pop_max_time; + + for (int t=6; t < 7; t+=20) { switch (t) { case 1: { input.open("/opt/ptu5/opt/customer_281/etc/psa_tariff/tariff01.json"); @@ -123,6 +176,7 @@ int main() { return 0; +#endif #if 0