/* * Created by Martin on 07/11/2017. * * 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 TWOBLUECUBES_CATCH_MATCHERS_FLOATING_H_INCLUDED #define TWOBLUECUBES_CATCH_MATCHERS_FLOATING_H_INCLUDED #include "catch_matchers.h" #include #include namespace Catch { namespace Matchers { namespace Floating { enum class FloatingPointKind : uint8_t; struct WithinAbsMatcher : MatcherBase { WithinAbsMatcher(double target, double margin); bool match(double const& matchee) const override; std::string describe() const override; private: double m_target; double m_margin; }; struct WithinUlpsMatcher : MatcherBase { WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType); bool match(double const& matchee) const override; std::string describe() const override; private: double m_target; int m_ulps; FloatingPointKind m_type; }; } // namespace Floating Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff); Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff); Floating::WithinAbsMatcher WithinAbs(double target, double margin); // The following functions create the actual matcher objects. // This allows the types to be inferred // StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); // StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); // StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); // StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); } // namespace Matchers } // namespace Catch #endif // TWOBLUECUBES_CATCH_MATCHERS_FLOATING_H_INCLUDED