diff options
author | Manoj Srivastava <srivasta@debian.org> | 2016-01-27 13:11:31 -0800 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2016-01-27 13:11:31 -0800 |
commit | 02819db3483514d49df7ec3f7e372b5aeb831466 (patch) | |
tree | 6a86adac74beac293bc688dafcfa1709a6476901 /vendor/bandit/bandit/assertion_frameworks/matchers/BeCloseTo.h | |
parent | 2a61dffe127e22c1aaf955db6f085ac2eefbebba (diff) | |
parent | 6f6de67c70fd98815088ce49f046f48f88ea35bd (diff) |
Merge branch 'upstream'
Signed-off-by: Manoj Srivastava <srivasta@debian.org>
# Conflicts:
# src/CMakeLists.txt
# src/config.h
# src/lua/llimits.h
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks/matchers/BeCloseTo.h')
-rw-r--r-- | vendor/bandit/bandit/assertion_frameworks/matchers/BeCloseTo.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/assertion_frameworks/matchers/BeCloseTo.h b/vendor/bandit/bandit/assertion_frameworks/matchers/BeCloseTo.h new file mode 100644 index 00000000..e4507c4c --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/matchers/BeCloseTo.h @@ -0,0 +1,55 @@ +#ifndef BANDIT_BECLOSETO_H +#define BANDIT_BECLOSETO_H + +#include "Matcher.h" + +namespace bandit { namespace Matchers { + + template<typename T> + class BeCloseTo : public Matcher + { + public: + explicit BeCloseTo(const T& expectedValue): Matcher(), _expectedValue(expectedValue), _threshold(0.01) {} + + BeCloseTo<T>& within(float threshold) + { + _threshold = threshold; + return *this; + } + + template<typename U> + bool matches(const U& actualValue) const + { + return this->subtractable_types_match(actualValue, _expectedValue); + } + + + protected: + virtual std::string failure_message_end() const + { + std::ostringstream ss; + ss << "be close to <" << _expectedValue << ">" << " (within " << _threshold << ")"; + return ss.str(); + } + + private: + template<typename U, typename V> + bool subtractable_types_match(const U& actualValue, const V& expectedValue) const + { + return (actualValue > (expectedValue - _threshold)) && (actualValue < (expectedValue + _threshold)); + } + + + private: + const T& _expectedValue; + float _threshold; + }; + + template<typename T> + BeCloseTo<T> be_close_to(const T& expectedValue) + { + return BeCloseTo<T>(expectedValue); + } +}} + +#endif // BANDIT_BECLOSETO_H |