Reorganizing unit tests
Unit tests for the toolkit are consolidated into one test module with a separate test suite for related API functions.
This commit is contained in:
@@ -24,41 +24,62 @@ endif(UNIX)
|
|||||||
IF(MSVC)
|
IF(MSVC)
|
||||||
set(Boost_DEBUG OFF)
|
set(Boost_DEBUG OFF)
|
||||||
set(Boost_DETAILED_FAILURE_MSG OFF)
|
set(Boost_DETAILED_FAILURE_MSG OFF)
|
||||||
set(Boost_USE_STATIC_LIBS ON)
|
set(Boost_USE_STATIC_LIBS OFF)
|
||||||
ENDIF(MSVC)
|
ENDIF(MSVC)
|
||||||
|
|
||||||
set(Boost_THREAD_FOUND OFF)
|
set(Boost_THREAD_FOUND OFF)
|
||||||
find_package(Boost COMPONENTS unit_test_framework system thread filesystem)
|
find_package(Boost COMPONENTS unit_test_framework filesystem)
|
||||||
include_directories (${Boost_INCLUDE_DIRS})
|
include_directories (${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
|
||||||
#I like to keep test files in a separate source directory called test
|
set(toolkit_test_srcs
|
||||||
file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test_*.cpp)
|
test_toolkit.cpp
|
||||||
|
test_project.cpp
|
||||||
|
test_hydraulics.cpp
|
||||||
|
test_quality.cpp
|
||||||
|
test_report.cpp
|
||||||
|
test_analysis.cpp
|
||||||
|
test_node.cpp
|
||||||
|
test_demand.cpp
|
||||||
|
test_link.cpp
|
||||||
|
# test_pump.cpp
|
||||||
|
test_pattern.cpp
|
||||||
|
# test_curve.cpp
|
||||||
|
test_control.cpp)
|
||||||
|
|
||||||
add_library(shared_test OBJECT shared_test.cpp)
|
add_executable(test_toolkit ${toolkit_test_srcs})
|
||||||
|
|
||||||
|
target_link_libraries(test_toolkit ${Boost_LIBRARIES} epanet2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#I like to keep test files in a separate source directory called test
|
||||||
|
#file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test_*.cpp)
|
||||||
|
|
||||||
|
#add_library(shared_test OBJECT shared_test.cpp)
|
||||||
|
|
||||||
#Run through each source
|
#Run through each source
|
||||||
foreach(testSrc ${TEST_SRCS})
|
#foreach(testSrc ${TEST_SRCS})
|
||||||
#Extract the filename without an extension (NAME_WE)
|
# #Extract the filename without an extension (NAME_WE)
|
||||||
get_filename_component(testName ${testSrc} NAME_WE)
|
# get_filename_component(testName ${testSrc} NAME_WE)
|
||||||
|
#
|
||||||
#Add compile target
|
# #Add compile target
|
||||||
IF(${testName} MATCHES "test_reent")
|
# IF(${testName} MATCHES "test_reent")
|
||||||
add_executable(${testName} ${testSrc})
|
# add_executable(${testName} ${testSrc})
|
||||||
ELSE (TRUE)
|
# ELSE (TRUE)
|
||||||
add_executable(${testName} ${testSrc} $<TARGET_OBJECTS:shared_test>)
|
# add_executable(${testName} ${testSrc} $<TARGET_OBJECTS:shared_test>)
|
||||||
ENDIF(${testName} MATCHES "test_reent")
|
# ENDIF(${testName} MATCHES "test_reent")
|
||||||
|
#
|
||||||
#link to Boost libraries AND your targets and dependencies
|
# #link to Boost libraries AND your targets and dependencies
|
||||||
IF(MSVC)
|
# IF(MSVC)
|
||||||
target_link_libraries(${testName} ${Boost_LIBRARIES} epanet2 epanet-output)
|
# target_link_libraries(${testName} ${Boost_LIBRARIES} epanet2 epanet-output)
|
||||||
ELSE(TRUE)
|
# ELSE(TRUE)
|
||||||
target_link_libraries(${testName} ${Boost_LIBRARIES} pthread epanet2 epanet-output)
|
# target_link_libraries(${testName} ${Boost_LIBRARIES} pthread epanet2 epanet-output)
|
||||||
ENDIF(MSVC)
|
# ENDIF(MSVC)
|
||||||
|
#
|
||||||
#Finally add it to test execution
|
# #Finally add it to test execution
|
||||||
#Notice the WORKING_DIRECTORY and COMMAND
|
# #Notice the WORKING_DIRECTORY and COMMAND
|
||||||
add_test(NAME ${testName}
|
# add_test(NAME ${testName}
|
||||||
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testName}
|
# COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testName}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||||
endforeach(testSrc)
|
#endforeach(testSrc)
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
//
|
|
||||||
// Hack to get boost unit test to compile faster
|
|
||||||
//
|
|
||||||
|
|
||||||
#include <boost/test/included/unit_test.hpp>
|
|
||||||
@@ -1,49 +1,23 @@
|
|||||||
//
|
/*
|
||||||
// test_rprtanlys.cpp
|
******************************************************************************
|
||||||
//
|
Project: OWA EPANET
|
||||||
// Date Created: February 28, 2019
|
Version: 2.2
|
||||||
//
|
Module: test_analysis.cpp
|
||||||
// Author: Michael E. Tryby
|
Description: Tests EPANET toolkit api functions
|
||||||
// US EPA - ORD/NRMRL
|
Authors: see AUTHORS
|
||||||
//
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE hydqual
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_rprtanlys)
|
BOOST_AUTO_TEST_SUITE (test_analysis)
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
double array[5];
|
|
||||||
|
|
||||||
std::vector<double> test;
|
|
||||||
std::vector<double> ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08,
|
|
||||||
0.0089173150106518495, 0.99999998187144024};
|
|
||||||
|
|
||||||
error = EN_solveH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_solveQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
|
|
||||||
for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) {
|
|
||||||
error = EN_getstatistic(ph, i, &array[i]);
|
|
||||||
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]);
|
|
||||||
BOOST_CHECK(error == 251);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
|
BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose)
|
||||||
{
|
{
|
||||||
@@ -1,5 +1,15 @@
|
|||||||
// Test of EN_addrule, EN_deletenode & EN_deletelink EPANET API Functions
|
/*
|
||||||
#define _CRT_SECURE_NO_DEPRECATE
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_control.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is a test for the API functions that adds rules and deletes
|
This is a test for the API functions that adds rules and deletes
|
||||||
@@ -8,9 +18,10 @@ node or link appearing in any simple or rule-based controls.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "rules"
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
char R1[] = "RULE 1 \n IF NODE 2 LEVEL < 100 \n THEN LINK 9 STATUS = OPEN";
|
char R1[] = "RULE 1 \n IF NODE 2 LEVEL < 100 \n THEN LINK 9 STATUS = OPEN";
|
||||||
@@ -19,7 +30,7 @@ char R3[] = "RULE 3\nIF NODE 23 PRESSURE ABOVE 140\nAND NODE 2 LEVEL > 120\n"
|
|||||||
"THEN LINK 113 STATUS = CLOSED\nELSE LINK 22 STATUS = CLOSED";
|
"THEN LINK 113 STATUS = CLOSED\nELSE LINK 22 STATUS = CLOSED";
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_addrule)
|
BOOST_AUTO_TEST_SUITE (test_controls)
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_add_get_rule, FixtureOpenClose)
|
BOOST_FIXTURE_TEST_CASE(test_add_get_rule, FixtureOpenClose)
|
||||||
{
|
{
|
||||||
@@ -1,18 +1,23 @@
|
|||||||
//
|
|
||||||
// test_demand_categories.cpp
|
|
||||||
//
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is a test for the demand categories names get\set APIs
|
******************************************************************************
|
||||||
A demand category name is set, the network is saved, reopened and the new demand category name is checked.
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_analysis.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "demands"
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_demands)
|
BOOST_AUTO_TEST_SUITE (test_demand)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_categories_save)
|
BOOST_AUTO_TEST_CASE(test_categories_save)
|
||||||
{
|
{
|
||||||
@@ -41,7 +46,7 @@ BOOST_AUTO_TEST_CASE(test_categories_save)
|
|||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demands/test_categories_save"))
|
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demand/test_categories_save"))
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int Nindex, ndem;
|
int Nindex, ndem;
|
||||||
@@ -59,11 +64,11 @@ BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("tes
|
|||||||
error = EN_getnumdemands(ph, Nindex, &ndem);
|
error = EN_getnumdemands(ph, Nindex, &ndem);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_CHECK(ndem == 1);
|
BOOST_CHECK(ndem == 1);
|
||||||
|
|
||||||
char demname[80];
|
char demname[80];
|
||||||
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
BOOST_CHECK(check_string(demname, "Demand category name"));
|
BOOST_CHECK(check_string(demname, "Demand category name"));
|
||||||
|
|
||||||
error = EN_close(ph);
|
error = EN_close(ph);
|
||||||
85
tests/test_hydraulics.cpp
Normal file
85
tests/test_hydraulics.cpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_hydraulics.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE (test_hydraulics)
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_solveH, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
error = EN_solveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_hyd_step, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
int flag = 00;
|
||||||
|
long t, tstep;
|
||||||
|
|
||||||
|
error = EN_openH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_initH(ph, flag);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = EN_runH(ph, &t);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_nextH(ph, &tstep);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
} while (tstep > 0);
|
||||||
|
|
||||||
|
error = EN_closeH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_hydr_save, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
error = EN_solveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_saveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_report(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_hydr_savefile, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
error = EN_solveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_savehydfile(ph, "test_savefile.hyd");
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
BOOST_CHECK(boost::filesystem::exists("test_savefile.hyd") == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_hydr_usefile, FixtureOpenClose, * boost::unit_test::depends_on("test_hydraulics/test_hydr_savefile"))
|
||||||
|
{
|
||||||
|
error = EN_usehydfile(ph, "test_savefile.hyd");
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_solveQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
@@ -1,163 +0,0 @@
|
|||||||
//
|
|
||||||
// test_hydrqual.cpp
|
|
||||||
//
|
|
||||||
// Date Created: February 28, 2019
|
|
||||||
//
|
|
||||||
// Author: Michael E. Tryby
|
|
||||||
// US EPA - ORD/NRMRL
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE hydrqual
|
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_hydrqual)
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_solveH_solveQ, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
error = EN_solveH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_solveQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_report(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_hyd_step, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
int flag = 00;
|
|
||||||
long t, tstep;
|
|
||||||
|
|
||||||
error = EN_openH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_initH(ph, flag);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
do {
|
|
||||||
error = EN_runH(ph, &t);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_nextH(ph, &tstep);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
} while (tstep > 0);
|
|
||||||
|
|
||||||
error = EN_closeH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_qual_step, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
int flag = 0;
|
|
||||||
long t, tstep;
|
|
||||||
|
|
||||||
error = EN_solveH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_openQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_initQ(ph, flag);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
do {
|
|
||||||
error = EN_runQ(ph, &t);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_stepQ(ph, &tstep);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
} while (tstep > 0);
|
|
||||||
|
|
||||||
error = EN_closeQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_progressive_step, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
int flag = EN_NOSAVE;
|
|
||||||
long t, tstep_h, tstep_q;
|
|
||||||
|
|
||||||
error = EN_openH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_initH(ph, flag);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_openQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_initQ(ph, flag);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
do {
|
|
||||||
error = EN_runH(ph, &t);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_runQ(ph, &t);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_nextH(ph, &tstep_h);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_nextQ(ph, &tstep_q);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
} while (tstep_h > 0);
|
|
||||||
|
|
||||||
error = EN_closeH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_closeQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_hydr_save, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
error = EN_solveH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_saveH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_report(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_hydr_savefile, FixtureOpenClose)
|
|
||||||
{
|
|
||||||
string hyd_file("test_savefile.hyd");
|
|
||||||
|
|
||||||
error = EN_solveH(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_savehydfile(ph, hyd_file.c_str());
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
BOOST_CHECK(filesystem::exists(hyd_file) == true);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_hydr_usefile, FixtureOpenClose, * unit_test::depends_on("test_hydrqual/test_hydr_savefile"))
|
|
||||||
{
|
|
||||||
string hyd_file("test_savefile.hyd");
|
|
||||||
|
|
||||||
error = EN_usehydfile(ph, hyd_file.c_str());
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
|
|
||||||
error = EN_solveQ(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
|
||||||
@@ -1,17 +1,20 @@
|
|||||||
// Test of ENsetlinktype EPANET API Function
|
|
||||||
#define _CRT_SECURE_NO_DEPRECATE
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is a test for the API function that changes a link's type.
|
******************************************************************************
|
||||||
Two links in Net1.inp are changed: Pipe 113 is reversed with a CV added
|
Project: OWA EPANET
|
||||||
and Pipe 121 is changed to a 100 psi PRV. After running the revised model,
|
Version: 2.2
|
||||||
at hour 0 the flow in Pipe 113 should be zero and the pressure at node 31
|
Module: test_link.cpp
|
||||||
of the PRV 121 should be 100.
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "link"
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_link)
|
BOOST_AUTO_TEST_SUITE (test_link)
|
||||||
@@ -86,12 +89,8 @@ BOOST_AUTO_TEST_CASE(test_setlinktype)
|
|||||||
EN_deleteproject(&ph);
|
EN_deleteproject(&ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_link_setid_save)
|
||||||
BOOST_AUTO_TEST_SUITE(setid_save_reopen)
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_setid_save)
|
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
@@ -120,7 +119,7 @@ BOOST_AUTO_TEST_CASE(test_setid_save)
|
|||||||
EN_deleteproject(&ph);
|
EN_deleteproject(&ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_setid_reopen, * boost::unit_test::depends_on("setid_save_reopen/test_setid_save"))
|
BOOST_AUTO_TEST_CASE(test_link_setid_reopen, * boost::unit_test::depends_on("test_link/test_link_setid_save"))
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int index;
|
int index;
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
// Test of EPANET's Network Building Functions
|
/*
|
||||||
//
|
******************************************************************************
|
||||||
// This is a test of the API functions EN_setjuncdata, EN_settankdata & EN_setpipedata
|
Project: OWA EPANET
|
||||||
//
|
Version: 2.2
|
||||||
|
Module: test_net_builder.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "net_builder"
|
#define BOOST_TEST_MODULE "net_builder"
|
||||||
|
|
||||||
@@ -246,7 +254,7 @@ BOOST_AUTO_TEST_CASE(test_open_net1, * boost::unit_test::depends_on("test_net_bu
|
|||||||
EN_createproject(&ph);
|
EN_createproject(&ph);
|
||||||
error = EN_open(ph, "net_builder.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
error = EN_open(ph, "net_builder.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_getnodeindex(ph, (char *)"2", &Nindex);
|
error = EN_getnodeindex(ph, (char *)"2", &Nindex);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
@@ -351,7 +359,7 @@ BOOST_FIXTURE_TEST_CASE(test_save_net2, FixtureInitClose)
|
|||||||
BOOST_AUTO_TEST_CASE(test_reopen_net2, *boost::unit_test::depends_on("test_net_builder/test_save_net2"))
|
BOOST_AUTO_TEST_CASE(test_reopen_net2, *boost::unit_test::depends_on("test_net_builder/test_save_net2"))
|
||||||
{
|
{
|
||||||
int error, index;
|
int error, index;
|
||||||
|
|
||||||
double p1_2, p2_2;
|
double p1_2, p2_2;
|
||||||
double q1_2, q2_2;
|
double q1_2, q2_2;
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
//
|
/*
|
||||||
// test_node.cpp
|
******************************************************************************
|
||||||
//
|
Project: OWA EPANET
|
||||||
// Date Created: February 8, 2019
|
Version: 2.2
|
||||||
//
|
Module: test_node.cpp
|
||||||
// Author: Michael E. Tryby
|
Description: Tests EPANET toolkit api functions
|
||||||
// US EPA - ORD/NRMRL
|
Authors: see AUTHORS
|
||||||
//
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "node"
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (node_props_after_open)
|
BOOST_AUTO_TEST_SUITE (test_node)
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_junc_props, FixtureOpenClose)
|
BOOST_FIXTURE_TEST_CASE(test_junc_props, FixtureOpenClose)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
// Test of the EN_setpatternid, EN_setcurveid, EN_deletepattern & EN_deletecurve
|
/*
|
||||||
// EPANET 2.2 API functions
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_pattern.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "pattern_curve"
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (pattern)
|
BOOST_AUTO_TEST_SUITE (pattern)
|
||||||
@@ -1,17 +1,23 @@
|
|||||||
//
|
/*
|
||||||
// test_project.cpp
|
******************************************************************************
|
||||||
//
|
Project: OWA EPANET
|
||||||
// Date Created: January 24, 2018
|
Version: 2.2
|
||||||
//
|
Module: test_project.cpp
|
||||||
// Author: Michael E. Tryby
|
Description: Tests EPANET toolkit api functions
|
||||||
// US EPA - ORD/NRMRL
|
Authors: see AUTHORS
|
||||||
//
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "project"
|
|
||||||
|
|
||||||
#include "shared_test.hpp"
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
using namespace boost;
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_project)
|
BOOST_AUTO_TEST_SUITE (test_project)
|
||||||
|
|
||||||
@@ -61,14 +67,14 @@ BOOST_AUTO_TEST_CASE(test_save)
|
|||||||
error = EN_saveinpfile(ph_save, "test_reopen.inp");
|
error = EN_saveinpfile(ph_save, "test_reopen.inp");
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
BOOST_CHECK(filesystem::exists("test_reopen.inp") == true);
|
BOOST_CHECK(boost::filesystem::exists("test_reopen.inp") == true);
|
||||||
|
|
||||||
error = EN_close(ph_save);
|
error = EN_close(ph_save);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
EN_deleteproject(&ph_save);
|
EN_deleteproject(&ph_save);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_save"))
|
BOOST_AUTO_TEST_CASE(test_reopen, * boost::unit_test::depends_on("test_project/test_save"))
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
@@ -100,7 +106,6 @@ BOOST_AUTO_TEST_CASE(test_run)
|
|||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(test_proj_fixture)
|
BOOST_AUTO_TEST_SUITE(test_proj_fixture)
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose)
|
BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose)
|
||||||
101
tests/test_quality.cpp
Normal file
101
tests/test_quality.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_quality.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE (test_quality)
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_solveQ, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
error = EN_solveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_solveQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_report(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_qual_step, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
int flag = 0;
|
||||||
|
long t, tstep;
|
||||||
|
|
||||||
|
error = EN_solveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_openQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_initQ(ph, flag);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = EN_runQ(ph, &t);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_stepQ(ph, &tstep);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
} while (tstep > 0);
|
||||||
|
|
||||||
|
error = EN_closeQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_CASE(test_progressive_step, FixtureOpenClose)
|
||||||
|
{
|
||||||
|
int flag = EN_NOSAVE;
|
||||||
|
long t, tstep_h, tstep_q;
|
||||||
|
|
||||||
|
error = EN_openH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_initH(ph, flag);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_openQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_initQ(ph, flag);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = EN_runH(ph, &t);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_runQ(ph, &t);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_nextH(ph, &tstep_h);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_nextQ(ph, &tstep_q);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
} while (tstep_h > 0);
|
||||||
|
|
||||||
|
error = EN_closeH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_closeQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* test_reent.cpp
|
******************************************************************************
|
||||||
*
|
Project: OWA EPANET
|
||||||
* Created: 8/30/2018
|
Version: 2.2
|
||||||
* Author: Michael E. Tryby
|
Module: test_reent.cpp
|
||||||
* US EPA - ORD/NRMRL
|
Description: Tests EPANET toolkit api functions
|
||||||
*
|
Authors: see AUTHORS
|
||||||
* Multi-threading / reentrancy test for EPANET Toolkit API.
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|||||||
51
tests/test_report.cpp
Normal file
51
tests/test_report.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_report.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
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> ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08,
|
||||||
|
0.0089173150106518495, 0.99999998187144024};
|
||||||
|
|
||||||
|
error = EN_solveH(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_solveQ(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
|
||||||
|
for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) {
|
||||||
|
error = EN_getstatistic(ph, i, &array[i]);
|
||||||
|
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]);
|
||||||
|
BOOST_CHECK(error == 251);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
65
tests/test_toolkit.cpp
Normal file
65
tests/test_toolkit.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_toolkit.cpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE toolkit
|
||||||
|
#define BOOST_ALL_DYN_LINK
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "test_toolkit.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
// Custom test to check the minimum number of correct decimal digits between
|
||||||
|
// the test and the ref vectors.
|
||||||
|
boost::test_tools::predicate_result check_cdd_double(std::vector<double>& test,
|
||||||
|
std::vector<double>& ref, long cdd_tol){
|
||||||
|
double tmp, min_cdd = 10.0;
|
||||||
|
|
||||||
|
// TODO: What if the vectors aren't the same length?
|
||||||
|
|
||||||
|
std::vector<double>::iterator test_it;
|
||||||
|
std::vector<double>::iterator ref_it;
|
||||||
|
|
||||||
|
for (test_it = test.begin(), ref_it = ref.begin();
|
||||||
|
(test_it < test.end()) && (ref_it < ref.end());
|
||||||
|
++test_it, ++ref_it)
|
||||||
|
{
|
||||||
|
if (*test_it != *ref_it) {
|
||||||
|
// Compute log absolute error
|
||||||
|
tmp = abs(*test_it - *ref_it);
|
||||||
|
if (tmp < 1.0e-7)
|
||||||
|
tmp = 1.0e-7;
|
||||||
|
|
||||||
|
else if (tmp > 2.0)
|
||||||
|
tmp = 1.0;
|
||||||
|
|
||||||
|
tmp = -log10(tmp);
|
||||||
|
if (tmp < 0.0)
|
||||||
|
tmp = 0.0;
|
||||||
|
|
||||||
|
if (tmp < min_cdd)
|
||||||
|
min_cdd = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return floor(min_cdd) >= cdd_tol;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
|
||||||
|
{
|
||||||
|
if (ref.compare(test) == 0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
@@ -1,4 +1,18 @@
|
|||||||
|
/*
|
||||||
|
******************************************************************************
|
||||||
|
Project: OWA EPANET
|
||||||
|
Version: 2.2
|
||||||
|
Module: test_toolkit.hpp
|
||||||
|
Description: Tests EPANET toolkit api functions
|
||||||
|
Authors: see AUTHORS
|
||||||
|
Copyright: see AUTHORS
|
||||||
|
License: see LICENSE
|
||||||
|
Last Updated: 03/21/2019
|
||||||
|
******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_TOOLKIT_HPP
|
||||||
|
#define TEST_TOOLKIT_HPP
|
||||||
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -12,58 +26,9 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
|
|
||||||
#include "epanet2_2.h"
|
#include "epanet2_2.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Custom test to check the minimum number of correct decimal digits between
|
|
||||||
// the test and the ref vectors.
|
|
||||||
boost::test_tools::predicate_result check_cdd_double(std::vector<double>& test,
|
|
||||||
std::vector<double>& ref, long cdd_tol){
|
|
||||||
double tmp, min_cdd = 10.0;
|
|
||||||
|
|
||||||
// TODO: What if the vectors aren't the same length?
|
|
||||||
|
|
||||||
std::vector<double>::iterator test_it;
|
|
||||||
std::vector<double>::iterator ref_it;
|
|
||||||
|
|
||||||
for (test_it = test.begin(), ref_it = ref.begin();
|
|
||||||
(test_it < test.end()) && (ref_it < ref.end());
|
|
||||||
++test_it, ++ref_it)
|
|
||||||
{
|
|
||||||
if (*test_it != *ref_it) {
|
|
||||||
// Compute log absolute error
|
|
||||||
tmp = abs(*test_it - *ref_it);
|
|
||||||
if (tmp < 1.0e-7)
|
|
||||||
tmp = 1.0e-7;
|
|
||||||
|
|
||||||
else if (tmp > 2.0)
|
|
||||||
tmp = 1.0;
|
|
||||||
|
|
||||||
tmp = -log10(tmp);
|
|
||||||
if (tmp < 0.0)
|
|
||||||
tmp = 0.0;
|
|
||||||
|
|
||||||
if (tmp < min_cdd)
|
|
||||||
min_cdd = tmp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return floor(min_cdd) >= cdd_tol;
|
|
||||||
}
|
|
||||||
|
|
||||||
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
|
|
||||||
{
|
|
||||||
if (ref.compare(test) == 0)
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define DATA_PATH_NET1 "./net1.inp"
|
#define DATA_PATH_NET1 "./net1.inp"
|
||||||
#define DATA_PATH_RPT "./test.rpt"
|
#define DATA_PATH_RPT "./test.rpt"
|
||||||
#define DATA_PATH_OUT "./test.out"
|
#define DATA_PATH_OUT "./test.out"
|
||||||
@@ -123,3 +88,10 @@ struct FixtureAfterStep{
|
|||||||
long t, tstep, tstop;
|
long t, tstep, tstop;
|
||||||
EN_Project ph;
|
EN_Project ph;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
boost::test_tools::predicate_result check_cdd_double(std::vector<double>& test,
|
||||||
|
std::vector<double>& ref, long cdd_tol);
|
||||||
|
boost::test_tools::predicate_result check_string(std::string test, std::string ref);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //TEST_TOOLKIT_HPP
|
||||||
Reference in New Issue
Block a user