-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Make with_tolerance reusable across other tests
Refinement of PR #527
- Loading branch information
Showing
2 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Copyright 2020 Samuel Debionne | ||
// | ||
// Distributed under the Boost Software License, Version 1.0 | ||
// See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt | ||
// | ||
#ifndef BOOST_GIL_TEST_TEST_UTILITY_WITH_TOLERANCE_HPP | ||
#define BOOST_GIL_TEST_TEST_UTILITY_WITH_TOLERANCE_HPP | ||
|
||
#include <cstdint> | ||
#include <ostream> | ||
#include <type_traits> | ||
|
||
namespace boost { namespace gil { | ||
|
||
namespace test { namespace utility { | ||
|
||
// Tolerance predicate for floating point comparison to use with BOOST_TEST_WITH. | ||
// See https://github.com/boostorg/core/pull/77 for details. | ||
template <typename T> | ||
struct with_tolerance | ||
{ | ||
with_tolerance(T tolerance) : tolerance(tolerance) | ||
{ | ||
} | ||
|
||
bool operator()(T lhs, T rhs) | ||
{ | ||
return (std::abs(lhs - rhs) <= tolerance); | ||
} | ||
|
||
private: | ||
T tolerance; | ||
}; | ||
|
||
}} // namespace test::utility | ||
|
||
}} // namespace boost::gil | ||
|
||
#endif |