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 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() {
#if BAD_NEUENAHR_AHRWEILER==1
std::ifstream input;
@ -167,8 +51,10 @@ int main() {
int pop_min_price;
int pop_max_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) {
switch (zone) {
case 1: {
@ -214,6 +100,7 @@ int main() {
if (isParsed) {
// test library functions
if (zone == 1) {
pop_min_time = get_minimal_parkingtime(&cfg);
pop_max_time = get_maximal_parkingtime(&cfg);
pop_min_price = get_minimal_parkingprice(&cfg);
@ -301,13 +188,72 @@ int main() {
//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));
}
}
#endif
QDateTime start(QDate(2024, 4, 14), QTime());
QDateTime end;
struct price_t price;
//start = QDateTime::currentDateTime();
int paymentOptionIndex = cfg.getCurrentPaymentOptionIndex(start);
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;
//}
}
}
}
}
}
#endif
#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/tariff02.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");
std::ifstream input(f.toUtf8().constData());
@ -329,24 +275,22 @@ int main() {
QDateTime start = QDateTime::currentDateTime();
// zone 1
//int timeSteps[9] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080};
// zone 2
//int timeSteps[3] = {60, 180, 1440};
//int timeSteps[] = {60, 180, 1440, 2880, 4320, 5670, 7200, 8640, 10080, 11520, 12960, 14400};
static QList<int> const timeSteps = Calculator::GetInstance().GetTimeSteps(&cfg);
qCritical() << "TimeSteps" << timeSteps;
// for (int i = 0 ; i < timeSteps.size(); ++i) {
// QDateTime end = start.addSecs(timeSteps.at(i)*60);
//
// double price = Calculator::GetInstance().GetCostFromDuration(
// &cfg,
// start,
// timeSteps.at(i));
// qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i) << "price=" << price;
//}
for (int i = 0 ; i < timeSteps.size(); ++i) {
QDateTime end = start.addSecs(timeSteps.at(i)*60);
double price = Calculator::GetInstance().GetCostFromDuration(
&cfg,
start,
timeSteps.at(i));
qDebug() << "GetCostFromDuration() time: " << timeSteps.at(i)
<< "(" << timeSteps.at(i)/60 << "h)"
<< "price=" << price;
}
}
#endif