Separating header for test_output
This commit is contained in:
@@ -28,7 +28,7 @@ if(MSVC)
|
||||
endif(MSVC)
|
||||
set(Boost_THREAD_FOUND OFF)
|
||||
find_package(Boost COMPONENTS system thread filesystem)
|
||||
include_directories (${Boost_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/tools/epanet-output/include)
|
||||
include_directories (${Boost_INCLUDE_DIRS})
|
||||
|
||||
|
||||
#I like to keep test files in a separate source directory called test
|
||||
|
||||
@@ -13,17 +13,64 @@
|
||||
//#define BOOST_TEST_DYN_LINK
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#define BOOST_TEST_MODULE "output"
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include "test_shared.hpp"
|
||||
#include "epanet_output.h"
|
||||
|
||||
|
||||
boost::test_tools::predicate_result check_cdd_float(std::vector<float>& test,
|
||||
std::vector<float>& ref, long cdd_tol){
|
||||
float tmp, min_cdd = 10.0;
|
||||
|
||||
// TODO: What if the vectors aren't the same length?
|
||||
|
||||
std::vector<float>::iterator test_it;
|
||||
std::vector<float>::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-7f)
|
||||
tmp = 1.0e-7f;
|
||||
|
||||
else if (tmp > 2.0f)
|
||||
tmp = 1.0f;
|
||||
|
||||
tmp = -log10(tmp);
|
||||
if (tmp < 0.0f)
|
||||
tmp = 0.0f;
|
||||
|
||||
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_OUTPUT "./example1.out"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE (test_output_auto)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(OpenCloseTest) {
|
||||
@@ -43,6 +90,30 @@ BOOST_AUTO_TEST_CASE(OpenCloseTest) {
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
||||
struct FixtureOutput{
|
||||
FixtureOutput() {
|
||||
path = std::string(DATA_PATH_OUTPUT);
|
||||
|
||||
error = ENR_init(&p_handle);
|
||||
ENR_clearError(p_handle);
|
||||
error = ENR_open(p_handle, path.c_str());
|
||||
|
||||
array = NULL;
|
||||
array_dim = 0;
|
||||
}
|
||||
~FixtureOutput() {
|
||||
free((void*)array);
|
||||
error = ENR_close(&p_handle);
|
||||
}
|
||||
|
||||
std::string path;
|
||||
int error;
|
||||
ENR_Handle p_handle;
|
||||
|
||||
float* array;
|
||||
int array_dim;
|
||||
};
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(test_output_fixture)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
#include "epanet2_2.h"
|
||||
#include "epanet_output.h"
|
||||
|
||||
|
||||
|
||||
// Custom test to check the minimum number of correct decimal digits between
|
||||
@@ -46,40 +46,6 @@ boost::test_tools::predicate_result check_cdd_double(std::vector<double>& test,
|
||||
return floor(min_cdd) >= cdd_tol;
|
||||
}
|
||||
|
||||
boost::test_tools::predicate_result check_cdd_float(std::vector<float>& test,
|
||||
std::vector<float>& ref, long cdd_tol){
|
||||
float tmp, min_cdd = 10.0;
|
||||
|
||||
// TODO: What if the vectors aren't the same length?
|
||||
|
||||
std::vector<float>::iterator test_it;
|
||||
std::vector<float>::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-7f)
|
||||
tmp = 1.0e-7f;
|
||||
|
||||
else if (tmp > 2.0f)
|
||||
tmp = 1.0f;
|
||||
|
||||
tmp = -log10(tmp);
|
||||
if (tmp < 0.0f)
|
||||
tmp = 0.0f;
|
||||
|
||||
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)
|
||||
@@ -116,30 +82,3 @@ struct FixtureOpenClose{
|
||||
int error;
|
||||
EN_Project ph;
|
||||
};
|
||||
|
||||
|
||||
#define DATA_PATH_OUTPUT "./example1.out"
|
||||
|
||||
struct FixtureOutput{
|
||||
FixtureOutput() {
|
||||
path = std::string(DATA_PATH_OUTPUT);
|
||||
|
||||
error = ENR_init(&p_handle);
|
||||
ENR_clearError(p_handle);
|
||||
error = ENR_open(p_handle, path.c_str());
|
||||
|
||||
array = NULL;
|
||||
array_dim = 0;
|
||||
}
|
||||
~FixtureOutput() {
|
||||
free((void*)array);
|
||||
error = ENR_close(&p_handle);
|
||||
}
|
||||
|
||||
std::string path;
|
||||
int error;
|
||||
ENR_Handle p_handle;
|
||||
|
||||
float* array;
|
||||
int array_dim;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user