Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
testing::internal::FloatingEqMatcher< FloatType >::Impl< T > Class Template Reference

#include <gmock-matchers.h>

Inheritance diagram for testing::internal::FloatingEqMatcher< FloatType >::Impl< T >:
Collaboration diagram for testing::internal::FloatingEqMatcher< FloatType >::Impl< T >:

Public Member Functions

 Impl (FloatType expected, bool nan_eq_nan, FloatType max_abs_error)
 
virtual bool MatchAndExplain (T value, MatchResultListener *listener) const
 
virtual void DescribeTo (::std::ostream *os) const
 
virtual void DescribeNegationTo (::std::ostream *os) const
 
- Public Member Functions inherited from testing::MatcherInterface< T >
- Public Member Functions inherited from testing::MatcherDescriberInterface
virtual ~MatcherDescriberInterface ()
 

Detailed Description

template<typename FloatType>
template<typename T>
class testing::internal::FloatingEqMatcher< FloatType >::Impl< T >

Definition at line 2110 of file gmock-matchers.h.

Constructor & Destructor Documentation

◆ Impl()

template<typename FloatType >
template<typename T >
testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::Impl ( FloatType expected,
bool nan_eq_nan,
FloatType max_abs_error )
inline

Definition at line 2112 of file gmock-matchers.h.

2113 : expected_(expected),
2114 nan_eq_nan_(nan_eq_nan),
2115 max_abs_error_(max_abs_error) {}

Member Function Documentation

◆ DescribeNegationTo()

template<typename FloatType >
template<typename T >
virtual void testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::DescribeNegationTo ( ::std::ostream * os) const
inlinevirtual

Reimplemented from testing::MatcherDescriberInterface.

Definition at line 2173 of file gmock-matchers.h.

2173 {
2174 // As before, get original precision.
2175 const ::std::streamsize old_precision = os->precision(
2176 ::std::numeric_limits<FloatType>::digits10 + 2);
2177 if (FloatingPoint<FloatType>(expected_).is_nan()) {
2178 if (nan_eq_nan_) {
2179 *os << "isn't NaN";
2180 } else {
2181 *os << "is anything";
2182 }
2183 } else {
2184 *os << "isn't approximately " << expected_;
2185 if (HasMaxAbsError()) {
2186 *os << " (absolute error > " << max_abs_error_ << ")";
2187 }
2188 }
2189 // Restore original precision.
2190 os->precision(old_precision);
2191 }
os_t os

◆ DescribeTo()

template<typename FloatType >
template<typename T >
virtual void testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::DescribeTo ( ::std::ostream * os) const
inlinevirtual

Implements testing::MatcherDescriberInterface.

Definition at line 2152 of file gmock-matchers.h.

2152 {
2153 // os->precision() returns the previously set precision, which we
2154 // store to restore the ostream to its original configuration
2155 // after outputting.
2156 const ::std::streamsize old_precision = os->precision(
2157 ::std::numeric_limits<FloatType>::digits10 + 2);
2158 if (FloatingPoint<FloatType>(expected_).is_nan()) {
2159 if (nan_eq_nan_) {
2160 *os << "is NaN";
2161 } else {
2162 *os << "never matches";
2163 }
2164 } else {
2165 *os << "is approximately " << expected_;
2166 if (HasMaxAbsError()) {
2167 *os << " (absolute error <= " << max_abs_error_ << ")";
2168 }
2169 }
2170 os->precision(old_precision);
2171 }

◆ MatchAndExplain()

template<typename FloatType >
template<typename T >
virtual bool testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::MatchAndExplain ( T value,
MatchResultListener * listener ) const
inlinevirtual

Implements testing::MatcherInterface< T >.

Definition at line 2117 of file gmock-matchers.h.

2118 {
2119 const FloatingPoint<FloatType> actual(value), expected(expected_);
2120
2121 // Compares NaNs first, if nan_eq_nan_ is true.
2122 if (actual.is_nan() || expected.is_nan()) {
2123 if (actual.is_nan() && expected.is_nan()) {
2124 return nan_eq_nan_;
2125 }
2126 // One is nan; the other is not nan.
2127 return false;
2128 }
2129 if (HasMaxAbsError()) {
2130 // We perform an equality check so that inf will match inf, regardless
2131 // of error bounds. If the result of value - expected_ would result in
2132 // overflow or if either value is inf, the default result is infinity,
2133 // which should only match if max_abs_error_ is also infinity.
2134 if (value == expected_) {
2135 return true;
2136 }
2137
2138 const FloatType diff = value - expected_;
2139 if (fabs(diff) <= max_abs_error_) {
2140 return true;
2141 }
2142
2143 if (listener->IsInterested()) {
2144 *listener << "which is " << diff << " from " << expected_;
2145 }
2146 return false;
2147 } else {
2148 return actual.AlmostEquals(expected);
2149 }
2150 }
void diff(const std::string &a, const std::string &b)
Definition jmp.cpp:18
#define value
Definition pkcs11.h:157
void fabs()
Here is the call graph for this function:

The documentation for this class was generated from the following file: