Merge branch 'dev' of https://github.com/OpenWaterAnalytics/EPANET into Mariosmsk-fix_bug_getdemandname

This commit is contained in:
Michael Tryby
2019-04-08 15:22:16 -04:00
37 changed files with 970 additions and 924 deletions

View File

@@ -30,7 +30,8 @@ set(toolkit_test_srcs
test_pattern.cpp
test_curve.cpp
test_control.cpp
test_net_builder.cpp)
test_net_builder.cpp
)
add_executable(test_toolkit ${toolkit_test_srcs})

View File

@@ -22,10 +22,12 @@ BOOST_AUTO_TEST_SUITE (test_analysis)
BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
{
int i;
double array[13];
std::vector<double> test;
std::vector<double> ref = {40.0, 0.001, 0.01, 0.5, 1.0, 0.0, 0.0, 1.0, 0.0, 75.0, 0.0, 0.0, 0.0};
std::vector<double> test(23);
double *array = test.data();
std::vector<double> ref = {40.0, 0.001, 0.01, 0.5, 1.0, 0.0, 0.0, 0.0, 75.0, 0.0, 0.0, 0.0,
1.0, 1.0, 10.0, 2.0, 10.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0};
error = EN_solveH(ph);
BOOST_REQUIRE(error == 0);
@@ -34,24 +36,25 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
BOOST_REQUIRE(error == 0);
for (i=EN_TRIALS; i<=EN_DEMANDCHARGE; i++) {
error = EN_getoption(ph, i, &array[i]);
for (i=EN_TRIALS; i<=EN_CONCENLIMIT; i++) {
error = EN_getoption(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 13);
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
error = EN_getoption(ph, 18, &array[0]);
double temp;
error = EN_getoption(ph, 25, &temp);
BOOST_CHECK(error == 251);
}
BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose)
{
int i;
long array[16];
std::vector<long> test;
std::vector<long> test(16);
long *array = test.data();
std::vector<long> ref = {86400, 3600, 300, 7200, 0, 3600, 0, 360, 0, 25, 0, 86400, 86400, 0, 3600, 0};
error = EN_solveH(ph);
@@ -62,14 +65,15 @@ BOOST_FIXTURE_TEST_CASE(test_anlys_gettimeparam, FixtureOpenClose)
for (i=EN_DURATION; i<=EN_NEXTEVENTTANK; i++) {
error = EN_gettimeparam(ph, i, &array[i]);
error = EN_gettimeparam(ph, i, array++);
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]);
long temp;
error = EN_gettimeparam(ph, 18, &temp);
BOOST_CHECK(error == 251);
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -35,6 +35,35 @@ BOOST_FIXTURE_TEST_CASE(test_curve_comments, FixtureOpenClose)
error = EN_getcomment(ph, EN_CURVE, index, comment);
BOOST_REQUIRE(error == 0);
BOOST_CHECK(check_string(comment, (char *)"Curve 1"));
// Test of EN_setcurve and EN_getcurve
int i;
char id1[] = "NewCurve";
int n1 = 5;
double X1[] = {16.88889, 19.5, 22.13889, 25.94445, 33.33334};
double Y1[] = {156.7, 146.5, 136.2, 117.9, 50.0};
int n2;
double X2[5], Y2[5];
char id2[EN_MAXID+1];
// Add data to a new curve
error = EN_addcurve(ph, id1);
BOOST_REQUIRE(error == 0);
error = EN_getcurveindex(ph, id1, &i);
BOOST_REQUIRE(error == 0);
error = EN_setcurve(ph, i, X1, Y1, n1);
BOOST_REQUIRE(error == 0);
// Retrieve data from curve
error = EN_getcurve(ph, i, id2, &n2, X2, Y2);
BOOST_REQUIRE(error == 0);
BOOST_CHECK(check_string(id2, id1));
BOOST_REQUIRE(n2 == n1);
for (i = 0; i < n1; i++)
{
BOOST_CHECK(X1[i] == X2[i]);
BOOST_CHECK(Y1[i] == Y2[i]);
}
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -11,6 +11,14 @@
******************************************************************************
*/
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#else
#include <stdlib.h>
#endif
#include <boost/test/unit_test.hpp>
#include "test_toolkit.hpp"
@@ -35,6 +43,9 @@ BOOST_AUTO_TEST_CASE(test_init_close)
struct FixtureInitClose {
FixtureInitClose() {
error = 0;
ph = NULL;
EN_createproject(&ph);
EN_init(ph, DATA_PATH_RPT, DATA_PATH_OUT, EN_GPM, EN_HW);
}
@@ -50,55 +61,55 @@ struct FixtureInitClose {
//BOOST_AUTO_TEST_CASE(net_builder_I)
//{
// int error = 0;
// int flag = 00;
// long t, tstep;
// int i, ind, Lindex, Nindex, Cindex;
// double h_orig, h_build, h_build_loaded;
// BOOST_AUTO_TEST_CASE(net_builder_I)
// {
// int error = 0;
// int flag = 00;
// long t, tstep;
// int i, ind, Lindex, Nindex, Cindex;
// double h_orig, h_build, h_build_loaded;
//
// // first we load Net1.inp, run it and record the head in Tank 2 at the end of the simulation (h_orig)
// EN_Project ph = NULL;
// EN_createproject(&ph);
// // first we load Net1.inp, run it and record the head in Tank 2 at the end of the simulation (h_orig)
// EN_Project ph = NULL;
// EN_createproject(&ph);
//
// std::string path_inp = std::string(DATA_PATH_NET1);
// std::string path_rpt = std::string(DATA_PATH_RPT);
// std::string path_out = std::string(DATA_PATH_OUT);
// std::string path_inp = std::string(DATA_PATH_NET1);
// std::string path_rpt = std::string(DATA_PATH_RPT);
// std::string path_out = std::string(DATA_PATH_OUT);
//
// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
// BOOST_REQUIRE(error == 0);
// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
// BOOST_REQUIRE(error == 0);
//
// error = EN_getnodeindex(ph, (char *)"2", &Nindex);
// BOOST_REQUIRE(error == 0);
// error = EN_getnodeindex(ph, (char *)"2", &Nindex);
// BOOST_REQUIRE(error == 0);
//
// error = EN_openH(ph);
// BOOST_REQUIRE(error == 0);
// error = EN_openH(ph);
// BOOST_REQUIRE(error == 0);
//
// error = EN_initH(ph, flag);
// BOOST_REQUIRE(error == 0);
// error = EN_initH(ph, flag);
// BOOST_REQUIRE(error == 0);
//
// do {
// error = EN_runH(ph, &t);
// BOOST_REQUIRE(error == 0);
// do {
// error = EN_runH(ph, &t);
// BOOST_REQUIRE(error == 0);
//
// // this is the head at the end of the simulation after loading the original Net1.inp
// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_orig);
// BOOST_REQUIRE(error == 0);
// // this is the head at the end of the simulation after loading the original Net1.inp
// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_orig);
// BOOST_REQUIRE(error == 0);
//
// error = EN_nextH(ph, &tstep);
// BOOST_REQUIRE(error == 0);
// error = EN_nextH(ph, &tstep);
// BOOST_REQUIRE(error == 0);
//
// } while (tstep > 0);
// } while (tstep > 0);
//
// error = EN_closeH(ph);
// BOOST_REQUIRE(error == 0);
// error = EN_closeH(ph);
// BOOST_REQUIRE(error == 0);
//
// error = EN_close(ph);
// BOOST_REQUIRE(error == 0);
// error = EN_close(ph);
// BOOST_REQUIRE(error == 0);
//
// EN_deleteproject(&ph);
//}
// EN_deleteproject(&ph);
// }
BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose)
{
@@ -121,8 +132,8 @@ BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose)
BOOST_REQUIRE(error == 0);
error = EN_setpattern(ph, 1, P, 12);
BOOST_REQUIRE(error == 0);
error = EN_setoption(ph, EN_DEFDEMANDPAT, 1);
BOOST_REQUIRE(error == 0);
//error = EN_setoption(ph, EN_DEFDEMANDPAT, 1);
//BOOST_REQUIRE(error == 0);
for (i = 0; i < 9; i++)
{
error = EN_addnode(ph, juncs[i], EN_JUNCTION);
@@ -131,6 +142,8 @@ BOOST_FIXTURE_TEST_CASE(test_build_net1, FixtureInitClose)
BOOST_REQUIRE(error == 0);
error = EN_setnodevalue(ph, i + 1, EN_BASEDEMAND, d[i]);
BOOST_REQUIRE(error == 0);
error = EN_setnodevalue(ph, i+1, EN_PATTERN, 1);
BOOST_REQUIRE(error == 0);
error = EN_setcoord(ph, i + 1, X[i], Y[i]);
BOOST_REQUIRE(error == 0);
//error = EN_setdemandpattern(ph, i + 1, 1, 1);

View File

@@ -33,12 +33,9 @@ BOOST_AUTO_TEST_CASE(add_set_pattern)
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Get the default pattern index
double dblPatIdx;
int defPatIdx;
// Assign the default pattern index
int defPatIdx = 1;
int patIdx;
EN_getoption(ph, EN_DEFDEMANDPAT, &dblPatIdx);
defPatIdx = (int)dblPatIdx;
// Rename the default pattern
EN_setpatternid(ph, defPatIdx, (char *)"Pat1");

View File

@@ -11,6 +11,8 @@
******************************************************************************
*/
#include <string.h>
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
@@ -109,37 +111,39 @@ BOOST_AUTO_TEST_SUITE(test_proj_fixture)
BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose)
{
// How is the API user supposed to know array size?
char c_test[3][80], c_ref[3][80];
char c_test[3][80];
strncpy(c_ref[0], " EPANET Example Network 1", 26);
strncpy(c_ref[1], "A simple example of modeling chlorine decay. Both bulk and", 59);
strncpy(c_ref[2], "wall reactions are included. ", 30);
// ref is an automatic variable and therefore doesn't need to be deleted
std::string ref[3] = {
" EPANET Example Network 1",
"A simple example of modeling chlorine decay. Both bulk and",
"wall reactions are included. "};
error = EN_gettitle(ph, c_test[0], c_test[1], c_test[2]);
BOOST_REQUIRE(error == 0);
for (int i = 0; i < 3; i++) {
std::string test (c_test[i]);
std::string ref (c_ref[i]);
BOOST_CHECK(check_string(test, ref));
}
for (int i = 0; i < 3; i++) {
std::string test (c_test[i]);
BOOST_CHECK(check_string(test, ref[i]));
}
// Need a test for EN_settitle
}
BOOST_FIXTURE_TEST_CASE(test_getcount, FixtureOpenClose)
{
int i, array[7];
int i;
std::vector<int> test;
std::vector<int> ref = { 11, 2, 13, 1, 1, 2, 0 };
std::vector<int> test(7);
int *array = test.data();
std::vector<int> ref = { 11, 2, 13, 1, 1, 2, 0 };
for (i=EN_NODECOUNT; i<=EN_RULECOUNT; i++) {
error = EN_getcount(ph, i, &array[i]);
error = EN_getcount(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 7);
BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
error = EN_getcount(ph, 7, &i);

View File

@@ -21,9 +21,10 @@ BOOST_AUTO_TEST_SUITE (test_report)
BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
{
int i;
double array[5];
std::vector<double> test;
std::vector<double> test(5);
double *array = test.data();
std::vector<double> ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08,
0.0089173150106518495, 0.99999998187144024};
@@ -35,15 +36,13 @@ BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) {
error = EN_getstatistic(ph, i, &array[i]);
error = EN_getstatistic(ph, i, array++);
BOOST_REQUIRE(error == 0);
}
test.assign(array, array + 5);
// BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end());
BOOST_CHECK(check_cdd_double(test, ref, 3));
error = EN_getstatistic(ph, 8, &array[0]);
double temp;
error = EN_getstatistic(ph, 8, &temp);
BOOST_CHECK(error == 251);
}

View File

@@ -14,7 +14,6 @@
#ifndef TEST_TOOLKIT_HPP
#define TEST_TOOLKIT_HPP
#include "epanet2_2.h"
@@ -25,6 +24,9 @@
struct FixtureOpenClose{
FixtureOpenClose() {
error = 0;
ph = NULL;
EN_createproject(&ph);
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
}
@@ -41,6 +43,9 @@ struct FixtureOpenClose{
struct FixtureAfterStep{
FixtureAfterStep() {
error = 0;
ph = NULL;
flag = 0;
tstop = 10800;