From 9f1b46b66a960bc50c39ae3ae18c8e376d134b3b Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Fri, 1 Mar 2019 15:16:27 -0500 Subject: [PATCH] Fixing bug in gettimeparam --- src/epanet.c | 12 +++++++++--- tests/test_rprtanlys.cpp | 26 ++++++++++++++++++++++++++ tests/test_shared.hpp | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index a89d648..fd18a07 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -1377,12 +1377,12 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value) case EN_REPORTSTART: *value = time->Rstart; break; - case EN_STATISTIC: - *value = rpt->Tstatflag; - break; case EN_RULESTEP: *value = time->Rulestep; break; + case EN_STATISTIC: + *value = rpt->Tstatflag; + break; case EN_PERIODS: *value = rpt->Nperiods; break; @@ -1392,6 +1392,10 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value) case EN_HTIME: *value = time->Htime; break; + case EN_QTIME: + *value = time->Qtime; + case EN_HALTFLAG: + break; case EN_NEXTEVENT: *value = time->Hstep; // find the lesser of the hydraulic time step length, // or the time to next full/empty tank @@ -1402,6 +1406,8 @@ int DLLEXPORT EN_gettimeparam(EN_Project p, int param, long *value) i = tanktimestep(p, value); *value = i; break; + default: + return 251; } return 0; } diff --git a/tests/test_rprtanlys.cpp b/tests/test_rprtanlys.cpp index f91e166..42e7af8 100644 --- a/tests/test_rprtanlys.cpp +++ b/tests/test_rprtanlys.cpp @@ -85,4 +85,30 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) BOOST_CHECK(error == 251); } +BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose) +{ + int i; + long array[16]; + + std::vector test; + vector ref = {86400, 3600, 300, 7200, 0, 3600, 0, 360, 0, 25, 0, 86400, 86400, 0, 3600, 0}; + + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_solveQ(ph); + BOOST_REQUIRE(error == 0); + + + for (i=EN_DURATION; i<=EN_NEXTEVENTTANK; i++) { + error = EN_gettimeparam(ph, i, &array[i]); + BOOST_REQUIRE(error == 0); + } + + test.assign(array, array + 16); + BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); + + error = EN_gettimeparam(ph, 18, &array[0]); + BOOST_CHECK(error == 251); +} BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_shared.hpp b/tests/test_shared.hpp index e852754..0cae52c 100644 --- a/tests/test_shared.hpp +++ b/tests/test_shared.hpp @@ -13,7 +13,7 @@ // the test and the ref vectors. boost::test_tools::predicate_result check_cdd_double(std::vector& test, std::vector& ref, long cdd_tol){ - float tmp, min_cdd = 10.0; + double tmp, min_cdd = 10.0; // TODO: What if the vectors aren't the same length?