Add test-cases

This commit is contained in:
Gerhard Hoffmann 2024-04-12 14:14:40 +02:00
parent aba38d2614
commit 449e618417

View File

@ -43,122 +43,6 @@ extern "C" char* strptime(const char* s,
#define NEUHAUSER_KIRCHDORF (0) #define NEUHAUSER_KIRCHDORF (0)
#define BAD_NEUENAHR_AHRWEILER (1) #define BAD_NEUENAHR_AHRWEILER (1)
#if NEUHAUSER_KIRCHDORF==1
static bool test_neuhauser_kirchdorf(int step, double cost) {
switch (step) {
case 30:
if (cost != 30) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 30;
return false;
}
break;
case 35:
if (cost != 40) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 40;
return false;
}
break;
case 40:
if (cost != 50) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 50;
return false;
}
break;
case 45:
if (cost != 60) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 60;
return false;
}
break;
case 50:
if (cost != 70) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 70;
return false;
}
break;
case 55:
if (cost != 80) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 80;
return false;
}
break;
case 60:
if (cost != 90) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 90;
return false;
}
break;
case 65:
if (cost != 100) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 100;
return false;
}
break;
case 70:
if (cost != 110) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 110;
return false;
}
break;
case 75:
if (cost != 120) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 120;
return false;
}
break;
case 80:
if (cost != 130) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 130;
return false;
}
break;
case 85:
if (cost != 140) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 140;
return false;
}
break;
case 90:
if (cost != 150) {
qCritical() << "ERROR COMPUTING COST"
<< "HAVE" << cost
<< "SHOULD" << 150;
return false;
}
break;
default:
break;
}
return true;
}
#endif
int main() { int main() {
#if BAD_NEUENAHR_AHRWEILER==1 #if BAD_NEUENAHR_AHRWEILER==1
std::ifstream input; std::ifstream input;
@ -167,8 +51,10 @@ int main() {
int pop_min_price; int pop_min_price;
int pop_max_price; int pop_max_price;
int pop_daily_card_price; int pop_daily_card_price;
int pop_carry_over;
int pop_carry_over_time_range_id;
for (int zone=1; zone < 2; ++zone) { for (int zone=2; zone < 3; ++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: {
@ -214,91 +100,151 @@ int main() {
if (isParsed) { if (isParsed) {
// test library functions // test library functions
pop_min_time = get_minimal_parkingtime(&cfg); if (zone == 1) {
pop_max_time = get_maximal_parkingtime(&cfg); pop_min_time = get_minimal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg); pop_max_time = get_maximal_parkingtime(&cfg);
pop_max_price = get_maximal_parkingprice(&cfg); pop_min_price = get_minimal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price; pop_max_price = get_maximal_parkingprice(&cfg);
pop_daily_card_price = cfg.getPaymentOptions().pop_daily_card_price;
qCritical() << " pop_min_time: " << pop_min_time; qCritical() << " pop_min_time: " << pop_min_time;
qCritical() << " pop_max_time: " << pop_max_time; qCritical() << " pop_max_time: " << pop_max_time;
qCritical() << " pop_min_price: " << pop_min_price; qCritical() << " pop_min_price: " << pop_min_price;
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;
static QList<int> const stepsConfigured static QList<int> const stepsConfigured
= QList(std::initializer_list<int>{ = QList(std::initializer_list<int>{
20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 1440}); 20, 40, 60, 80, 100, 120, 140, 160, 180, 200, 220, 240, 260, 1440});
//static QList<double> const cost //static QList<double> const cost
// = QList(std::initializer_list<double>{ // = QList(std::initializer_list<double>{
// 0, 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 500}); // 0, 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 500});
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg); static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps; qCritical() << "TimeSteps" << timeSteps;
if (stepsConfigured != timeSteps) { if (stepsConfigured != timeSteps) {
qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured; qCritical() << "TIME-STEPS SHOULD BE" << stepsConfigured;
return -1; return -1;
} }
QDateTime start = QDateTime::currentDateTime(); QDateTime start = QDateTime::currentDateTime();
struct price_t costs; struct price_t costs;
double price1 = 0; double price1 = 0;
double price2 = 0; double price2 = 0;
for (int m=0; m < 1440; ++m) { for (int m=0; m < 1440; ++m) {
start.setTime(QTime(0, 0, 0)); start.setTime(QTime(0, 0, 0));
start = start.addSecs(m*60); start = start.addSecs(m*60);
qCritical() << "START" << start.toString(Qt::ISODate); qCritical() << "START" << start.toString(Qt::ISODate);
//int Down = 0; //int Down = 0;
//int Up = 1; //int Up = 1;
// for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) { // for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++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;
// //
// int prevTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Down); // int prevTimeStep = compute_next_timestep(&cfg, timeSteps.at(i), Down);
// qCritical() << "prevTimeStep" << prevTimeStep; // qCritical() << "prevTimeStep" << prevTimeStep;
//} //}
CalcState cs; CalcState cs;
for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) { for (int i = 0, j=timeSteps.size() ; i < timeSteps.size(); --j, ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60); QDateTime end = start.addSecs(timeSteps.at(i)*60);
cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs); cs = compute_price_for_parking_ticket(&cfg, start, timeSteps.at(i), end, &costs);
if (cs.getStatus() != CalcState::State::SUCCESS) { if (cs.getStatus() != CalcState::State::SUCCESS) {
if (start.time().hour() >= 8 && start.time().hour() < 18) { if (start.time().hour() >= 8 && start.time().hour() < 18) {
qCritical() << "ERROR CALC-STATE-1=" << QString(cs); qCritical() << "ERROR CALC-STATE-1=" << QString(cs);
exit(-1); exit(-1);
} else { } else {
if (cs.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) { if (cs.getStatus() == CalcState::State::OUTSIDE_ALLOWED_PARKING_TIME) {
qCritical() << "CALC-STATE=" << QString(cs); qCritical() << "CALC-STATE=" << QString(cs);
continue; continue;
}
qCritical() << "ERROR CALC-STATE-2=" << QString(cs);
exit(-1);
} }
qCritical() << "ERROR CALC-STATE-2=" << QString(cs); }
price1 = costs.netto;
price2 = Calculator::GetInstance().GetCostFromDuration(&cfg, start, timeSteps.at(i));
if (price1 != price2) {
qCritical() << "ERROR DIFFERENT PRICES" << price1 << price2;
exit(-1); exit(-1);
} }
}
price1 = costs.netto;
price2 = Calculator::GetInstance().GetCostFromDuration(&cfg, start, timeSteps.at(i));
if (price1 != price2) { qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: "
qCritical() << "ERROR DIFFERENT PRICES" << price1 << price2; << timeSteps.at(i) << "PRICE=" << price1;
exit(-1);
//std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4,
// start.toString(Qt::ISODate).toStdString().c_str(),
// cost[i], false, true);
//qCritical() << "duration" << duration.c_str();
}
}
} // zone == 1
if (zone == 2) {
int const numOptions = cfg.getAllPaymentOptions().size();
#if 0
for (int payOpt=0; payOpt < numOptions; ++payOpt) {
pop_min_time = get_minimal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_max_time = get_maximal_parkingtime(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_min_price = get_minimal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_max_price = get_maximal_parkingprice(&cfg, PERMIT_TYPE::SHORT_TERM_PARKING, payOpt);
pop_daily_card_price = cfg.getPaymentOptions(payOpt).pop_daily_card_price;
pop_carry_over = cfg.getPaymentOptions(payOpt).pop_carry_over;
pop_carry_over_time_range_id = cfg.getPaymentOptions(payOpt).pop_carry_over_time_range_id;
qCritical() << QString(" pop_min_time[%1]: %2").arg(payOpt).arg(pop_min_time);
qCritical() << QString(" pop_max_time[%1]: %2").arg(payOpt).arg(pop_max_time);
qCritical() << QString(" pop_min_price[%1]: %2").arg(payOpt).arg(pop_min_price);
qCritical() << QString(" pop_max_price[%1]: %2").arg(payOpt).arg(pop_max_price);
qCritical() << QString(" pop_daily_card_price[%1]: %2").arg(payOpt).arg(pop_daily_card_price);
qCritical() << QString(" pop_carry_over[%1]: %2").arg(payOpt).arg(pop_carry_over);
qCritical() << QString("pop_carry_over_time_range_id[%1]: %2").arg(payOpt).arg(pop_carry_over_time_range_id);
if (pop_carry_over_time_range_id != -1) {
QTime const carryOverTimeRangeFrom = cfg.TimeRange.find(pop_carry_over_time_range_id)->second.time_range_from;
QTime const carryOverTimeRangeTo = cfg.TimeRange.find(pop_carry_over_time_range_id)->second.time_range_to;
qCritical() << QString(" timeRangeFrom[%1]: %2").arg(payOpt).arg(carryOverTimeRangeFrom.toString(Qt::ISODate));
qCritical() << QString(" timeRangeTo[%1]: %2").arg(payOpt).arg(carryOverTimeRangeTo.toString(Qt::ISODate));
} }
qCritical() << "compute_price_for_parking_ticket()/GetCostFromDuration() TIME: " }
<< timeSteps.at(i) << "PRICE=" << price1; #endif
QDateTime start(QDate(2024, 4, 14), QTime());
QDateTime end;
struct price_t price;
//std::string duration = Calculator::GetInstance().GetDurationFromCost(&cfg, 4, //start = QDateTime::currentDateTime();
// start.toString(Qt::ISODate).toStdString().c_str(),
// cost[i], false, true); int paymentOptionIndex = cfg.getCurrentPaymentOptionIndex(start);
//qCritical() << "duration" << duration.c_str(); if (paymentOptionIndex != -1) {
qCritical() << "paymentOptionIndex" << paymentOptionIndex;
QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg, paymentOptionIndex);
qCritical() << "TimeSteps" << timeSteps;
// QDateTime start = s.addSecs(offset * 60);
QList<int>::const_iterator step;
for (step = timeSteps.cbegin(); step != timeSteps.cend(); ++step) {
double cost = 0;
//if (compute_price_for_parking_ticket(&cfg, start, *step, end, &price)) {
// cost = price.netto;
//}
}
} }
} }
} }
@ -306,8 +252,8 @@ int main() {
#endif #endif
#if SCHOENAU_KOENIGSEE==1 #if SCHOENAU_KOENIGSEE==1
QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff01.json"); //QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff01.json");
//QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff02.json"); QString f("/opt/ptu5/opt/customer_332/etc/psa_tariff/tariff02.json");
std::ifstream input(f.toUtf8().constData()); std::ifstream input(f.toUtf8().constData());
@ -329,24 +275,22 @@ int main() {
QDateTime start = QDateTime::currentDateTime(); QDateTime start = QDateTime::currentDateTime();
// zone 1 // zone 1
//int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080}; //int timeSteps[] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080, 11520, 12960, 14400};
// zone 2
//int timeSteps[3] = {60, 180, 1440};
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg); static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps; qCritical() << "TimeSteps" << timeSteps;
// for (int i = 0 ; i < timeSteps.size(); ++i) { for (int i = 0 ; i < timeSteps.size(); ++i) {
// QDateTime end = start.addSecs(timeSteps.at(i)*60); QDateTime end = start.addSecs(timeSteps.at(i)*60);
//
// double price = Calculator::GetInstance().GetCostFromDuration( double price = Calculator::GetInstance().GetCostFromDuration(
// &cfg, &cfg,
// start, start,
// timeSteps.at(i)); timeSteps.at(i));
// qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) << "price=" << price; qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i)
//} << "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
}
} }
#endif #endif