improved tests

This commit is contained in:
Gerhard Hoffmann 2024-06-04 11:27:57 +02:00
parent e121cef17e
commit 068575f8e8

View File

@ -28,22 +28,23 @@ extern "C" char* strptime(const char* s,
#include <QDateTime> #include <QDateTime>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QSet>
#include <initializer_list>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include "calculator_functions.h" #include "calculator_functions.h"
#include "calculate_price.h" #include "calculate_price.h"
#define SZEGED (0) #define SZEGED (1)
#define SCHOENAU_KOENIGSEE (0) #define SCHOENAU_KOENIGSEE (0)
#define NEUHAUSER_KORNEUBURG (0) #define NEUHAUSER_KORNEUBURG (0)
#define NEUHAUSER_LINSINGER_MASCHINENBAU (0) #define NEUHAUSER_LINSINGER_MASCHINENBAU (0)
#define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0) #define NEUHAUSER_NORDISCHES_AUSBILDUNGSZENTRUM (0)
#define NEUHAUSER_BILEXA_GALTUER (0) #define NEUHAUSER_BILEXA_GALTUER (0)
#define NEUHAUSER_KIRCHDORF (0)
#define BAD_NEUENAHR_AHRWEILER (0) #define BAD_NEUENAHR_AHRWEILER (0)
#define NEUHAUSER_CHRISTOPH_REISEN (0) #define NEUHAUSER_CHRISTOPH_REISEN (0)
#define NEUHAUSER_PERNEGG_AN_DER_MUR (1) #define NEUHAUSER_PERNEGG_AN_DER_MUR (0)
#if NEUHAUSER_KIRCHDORF==1 #if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) { static bool test_neuhauser_kirchdorf(int step, double cost) {
@ -264,6 +265,18 @@ int main() {
price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET); price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::DAY_TICKET);
qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price; qCritical() << QString("line=%1 get_minimal_parkingprice:").arg(__LINE__) << price;
for (int h = 0; h < 24; ++h) {
start.setTime(QTime(h, 0, 0));
productStart = productEnd = QDateTime();
price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET, start, &productStart, &productEnd);
qCritical() << QString("line=%1 %2 price (%3-%4) :")
.arg(__LINE__)
.arg(start.time().toString(Qt::ISODate))
.arg(productStart.time().toString(Qt::ISODate))
.arg(productEnd.time().toString(Qt::ISODate))
<< price;
}
} }
#endif #endif
@ -344,7 +357,7 @@ int main() {
// 2024-05-05 10:02:30 // 2024-05-05 10:02:30
struct price_t costs; struct price_t costs;
double const cost[] = {600, 700, 800, 1600, 2400, 3000, 3600}; double const cost[] = {600, 700, 800, 1600, 2400, 3200, 4000};
double price1 = 0; double price1 = 0;
double price2 = 0; double price2 = 0;
@ -391,7 +404,7 @@ int main() {
int pop_carry_over; int pop_carry_over;
int pop_carry_over_time_range_id; int pop_carry_over_time_range_id;
for (int zone=6; zone < 7; ++zone) { for (int zone=1; zone < 2; ++zone) {
//for (int t=6; t < 7; t+=20) { //for (int t=6; t < 7; t+=20) {
switch (zone) { switch (zone) {
case 1: { case 1: {
@ -1044,9 +1057,179 @@ int main() {
&cfg, &cfg,
start, start,
timeSteps.at(i)); timeSteps.at(i));
qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) qCritical() << "zone" << zone
<< "(" << timeSteps.at(i)/60 << "h)" << "GetCostFromDuration() time: " << timeSteps.at(i)
<< "price=" << price; << "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
switch(timeSteps.at(i)) {
case 60:
if (zone == 1) {
if (price == 300.0) {
continue;
}
}
if (zone == 2) {
if (price == 300.0) {
continue;
}
}
if (zone == 3) {
if (price == 200.0) {
continue;
}
}
break;
case 180:
if (zone == 1) {
if (price == 700.0) {
continue;
}
}
if (zone == 2) {
if (price == 500.0) {
continue;
}
}
if (zone == 3) {
if (price == 400.0) {
continue;
}
}
break;
case 1440:
if (zone == 1) {
if (price == 900.0) {
continue;
}
}
if (zone == 2) {
if (price == 600.0) {
continue;
}
}
if (zone == 3) {
if (price == 500.0) {
continue;
}
}
break;
case 2880:
if (zone == 1) {
if (price == 1800.0) {
continue;
}
}
if (zone == 2) {
if (price == 1200.0) {
continue;
}
}
break;
case 4320:
if (zone == 1) {
if (price == 2700.0) {
continue;
}
}
if (zone == 2) {
if (price == 1800.0) {
continue;
}
}
break;
case 5760:
if (zone == 1) {
if (price == 3600.0) {
continue;
}
}
if (zone == 2) {
if (price == 2400.0) {
continue;
}
}
break;
case 7200:
if (zone == 1) {
if (price == 4500.0) {
continue;
}
}
if (zone == 2) {
if (price == 3000.0) {
continue;
}
}
break;
case 8640:
if (zone == 1) {
if (price == 5400.0) {
continue;
}
}
if (zone == 2) {
if (price == 3600.0) {
continue;
}
}
break;
case 10080:
if (zone == 1) {
if (price == 6300.0) {
continue;
}
}
if (zone == 2) {
if (price == 4200.0) {
continue;
}
}
break;
case 11520:
if (zone == 1) {
if (price == 7200.0) {
continue;
}
}
if (zone == 2) {
if (price == 4800.0) {
continue;
}
}
break;
case 12960:
if (zone == 1) {
if (price == 8100.0) {
continue;
}
}
if (zone == 2) {
if (price == 5400.0) {
continue;
}
}
break;
case 14400:
if (zone == 1) {
if (price == 9000.0) {
continue;
}
}
if (zone == 2) {
if (price == 6000.0) {
continue;
}
}
break;
default:
qCritical() << "ERROR zone" << zone
<< "GetCostFromDuration() time: " << timeSteps.at(i)
<< "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
exit(-1);
}
} }
} }
} }
@ -1427,15 +1610,25 @@ int main() {
exit(-1); exit(-1);
} }
QSet<uint32_t> const prices{700, 1400, 2100, 2800, 3500, 4200, 4900};
for (int i=0; i<timeSteps.size(); ++i) { for (int i=0; i<timeSteps.size(); ++i) {
int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up); int nextTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Up);
qCritical() << "nextTimeStep" << nextTimeStep; qCritical() << "nextTimeStep" << nextTimeStep;
uint32_t price = Calculator::GetInstance().GetPriceForTimeStep(&cfg, timeSteps.at(i), paymentOptionIndex); uint32_t price = Calculator::GetInstance().GetPriceForTimeStep(&cfg, timeSteps.at(i), paymentOptionIndex);
uint32_t duration = Calculator::GetInstance().GetDurationForPrice(&cfg, price); uint32_t duration = Calculator::GetInstance().GetDurationForPrice(&cfg, price);
if (!prices.contains(price)) {
qCritical() << "ERROR nextTimeStep relative to start:"
<< duration << start.addSecs(duration * 60).toString(Qt::ISODate)
<< "(price so far:" << price << ")";
exit(-1);
}
qCritical() << "nextTimeStep relative to start:" qCritical() << "nextTimeStep relative to start:"
<< duration << start.addSecs(duration * 60).toString(Qt::ISODate) << duration << start.addSecs(duration * 60).toString(Qt::ISODate)
<< "(price so far:" << price << ")"; << "(price so far:" << price << ")";
} }
} }
#endif #endif
@ -1470,6 +1663,11 @@ int main() {
CalcState cs = compute_price_for_daily_ticket(&cfg, start, end, CalcState cs = compute_price_for_daily_ticket(&cfg, start, end,
PERMIT_TYPE::DAY_TICKET_ADULT, PERMIT_TYPE::DAY_TICKET_ADULT,
&price); &price);
if (price.netto != 800) {
qCritical() << "ERROR(ADULT) start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (ADULT)" << price.netto;
exit(-1);
}
qCritical() << "start=" << start.toString(Qt::ISODate) qCritical() << "start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (ADULT)" << price.netto; << "end" << end.toString(Qt::ISODate) << "price (ADULT)" << price.netto;
} }
@ -1479,6 +1677,11 @@ int main() {
CalcState cs = compute_price_for_daily_ticket(&cfg, start, end, CalcState cs = compute_price_for_daily_ticket(&cfg, start, end,
PERMIT_TYPE::DAY_TICKET_TEEN, PERMIT_TYPE::DAY_TICKET_TEEN,
&price); &price);
if (price.netto != 400) {
qCritical() << "ERROR(TEEN) start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (TEEN)" << price.netto;
exit(-1);
}
qCritical() << "start=" << start.toString(Qt::ISODate) qCritical() << "start=" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "price (TEEN)" << price.netto; << "end" << end.toString(Qt::ISODate) << "price (TEEN)" << price.netto;
} }
@ -1501,6 +1704,11 @@ int main() {
if (isParsed) { if (isParsed) {
int const price = compute_product_price(&cfg, PERMIT_TYPE::FOOD_STAMP); int const price = compute_product_price(&cfg, PERMIT_TYPE::FOOD_STAMP);
if (price != 300) {
qCritical() << "ERROR price food stamp" << price;
exit(-1);
}
qCritical() << "price food stamp" << price; qCritical() << "price food stamp" << price;
} }
#endif #endif
@ -1542,6 +1750,170 @@ int main() {
<< "duration" << duration << "duration" << duration
<< "cost" << cost; << "cost" << cost;
switch(duration) {
case 30:
if (cost == 60.0) {
continue;
}
break;
case 35:
if (cost == 70.0) {
continue;
}
break;
case 40:
if (cost == 80.0) {
continue;
}
break;
case 45:
if (cost == 90.0) {
continue;
}
break;
case 50:
if (cost == 100.0) {
continue;
}
break;
case 55:
if (cost == 110.0) {
continue;
}
break;
case 60:
if (cost == 120.0) {
continue;
}
break;
case 65:
if (cost == 130.0) {
continue;
}
break;
case 70:
if (cost == 140.0) {
continue;
}
break;
case 75:
if (cost == 150.0) {
continue;
}
break;
case 80:
if (cost == 160.0) {
continue;
}
break;
case 85:
if (cost == 170.0) {
continue;
}
break;
case 90:
if (cost == 180.0) {
continue;
}
break;
case 95:
if (cost == 190.0) {
continue;
}
break;
case 100:
if (cost == 200.0) {
continue;
}
break;
case 105:
if (cost == 210.0) {
continue;
}
break;
case 110:
if (cost == 220.0) {
continue;
}
break;
case 115:
if (cost == 230.0) {
continue;
}
break;
case 120:
if (cost == 240.0) {
continue;
}
break;
case 125:
if (cost == 250.0) {
continue;
}
break;
case 130:
if (cost == 260.0) {
continue;
}
break;
case 135:
if (cost == 270.0) {
continue;
}
break;
case 140:
if (cost == 280.0) {
continue;
}
break;
case 145:
if (cost == 290.0) {
continue;
}
break;
case 150:
if (cost == 300.0) {
continue;
}
break;
case 155:
if (cost == 310.0) {
continue;
}
break;
case 160:
if (cost == 320.0) {
continue;
}
break;
case 165:
if (cost == 330.0) {
continue;
}
break;
case 170:
if (cost == 340.0) {
continue;
}
break;
case 175:
if (cost == 350.0) {
continue;
}
break;
case 180:
if (cost == 360.0) {
continue;
}
break;
default:
qCritical() << "ERROR(1) start" << start.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate)
<< "duration" << duration
<< "cost" << cost;
exit(-1);
}
//std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost); //std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 3, start.toString(Qt::ISODate).toStdString().c_str(), cost);
//Q_ASSERT(cost == duration*2.5); //Q_ASSERT(cost == duration*2.5);
//qCritical() << "start" << start.toString(Qt::ISODate) //qCritical() << "start" << start.toString(Qt::ISODate)
@ -1558,6 +1930,13 @@ int main() {
s.setTime(QTime(12, 0, 0)); s.setTime(QTime(12, 0, 0));
int duration = 30; int duration = 30;
double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, s, end, duration, nextDay, prePaid); double cost = Calculator::GetInstance().GetCostFromDuration(&cfg, 3, s, end, duration, nextDay, prePaid);
if (cost != 60.0) {
qCritical() << "ERROR(2) start" << s.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate)
<< "duration" << duration
<< "cost" << cost;
exit(-1);
}
qCritical() << "start" << s.toString(Qt::ISODate) qCritical() << "start" << s.toString(Qt::ISODate)
<< "end" << end.toString(Qt::ISODate) << "end" << end.toString(Qt::ISODate)
<< "duration" << duration << "duration" << duration
@ -1578,7 +1957,7 @@ int main() {
int pop_max_price; int pop_max_price;
int pop_daily_card_price; int pop_daily_card_price;
for (int zone=1; zone < 2; ++zone) { for (int zone = 1; zone < 2; ++zone) {
//for (int t=6; t < 7; t+=20) { //for (int t=6; t < 7; t+=20) {
switch (zone) { switch (zone) {
case 1: { case 1: {
@ -1632,6 +2011,10 @@ int main() {
qCritical() << " pop_max_price: " << pop_max_price; qCritical() << " pop_max_price: " << pop_max_price;
qCritical() << "pop_daily_card_price: " << pop_daily_card_price; qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
pop_daily_card_price = compute_product_price(&cfg, PERMIT_TYPE::DAY_TICKET);
qCritical() << "pop_daily_card_price: " << pop_daily_card_price;
if (pop_min_time > pop_max_time) { if (pop_min_time > pop_max_time) {
qCritical() << "ERROR pop_min_time > pop_max_time" qCritical() << "ERROR pop_min_time > pop_max_time"
<< pop_min_time << pop_max_time; << pop_min_time << pop_max_time;
@ -1778,7 +2161,7 @@ int main() {
m.insert(115, 499); m.insert(115, 499);
m.insert(120, 520); m.insert(120, 520);
m.insert(125, 524); m.insert(125, 542);
m.insert(130, 564); m.insert(130, 564);
m.insert(135, 585); m.insert(135, 585);
m.insert(140, 607); m.insert(140, 607);
@ -2197,17 +2580,19 @@ int main() {
return -1; return -1;
} }
// start = s.addSecs(offset * 60); // this->getDayTicketPrice(PERMIT_TYPE::DAY_TICKET)
// end = QDateTime();
//if (compute_duration_for_daily_ticket(&cfg, start, end)) {
//
// } else {
// qCritical() << "ERROR computing_duration_for_daily_ticket AT"
// << "start" << start.toString(Qt::ISODate);
// return -1;
// }
++cnt; // start = s.addSecs(offset * 60);
// end = QDateTime();
// if (compute_duration_for_daily_ticket(&cfg, start, end)) {
//
// } else {
// qCritical() << "ERROR computing_duration_for_daily_ticket AT"
// << "start" << start.toString(Qt::ISODate);
// return -1;
// }
// ++cnt;
} }
} }
} }