lixiaojun
2025-04-18 28ba54f194f1301c45aa30b44cd7b612855b8963
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
 
#include <math.h>
 
#include <boost/test/included/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;
}