Fixing bug in check_cdd
@@ -29,29 +29,37 @@ using namespace std;
// 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(std::vector<float>& test,
- std::vector<float>& ref, long cdd_tol)
-{
- float tmp, min_cdd = 100.0;
+ std::vector<float>& ref, long cdd_tol){
+ float tmp, min_cdd = 10.0;
- // TODO: What is the vectors aren't the same length?
+ // 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(); test_it < test.end(); ++test_it) {
- for (ref_it = ref.begin(); ref_it < ref.end(); ++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) {
- tmp = - log10f(abs(*test_it - *ref_it));
- if (tmp < min_cdd) min_cdd = tmp;
- }
+ // 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;
}
}
- if (min_cdd == 100.0)
- return true;
- else
- return floor(min_cdd) <= cdd_tol;
+ return floor(min_cdd) >= cdd_tol;
}
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
