Electroneum
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::MatcherDescriberInterface
virtual ~MatcherDescriberInterface ()

Detailed Description

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

Definition at line 1914 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 1916 of file gmock-matchers.h.

1917 : expected_(expected),
1918 nan_eq_nan_(nan_eq_nan),
1919 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 1977 of file gmock-matchers.h.

1977 {
1978 // As before, get original precision.
1981 if (FloatingPoint<FloatType>(expected_).is_nan()) {
1982 if (nan_eq_nan_) {
1983 *os << "isn't NaN";
1984 } else {
1985 *os << "is anything";
1986 }
1987 } else {
1988 *os << "isn't approximately " << expected_;
1989 if (HasMaxAbsError()) {
1990 *os << " (absolute error > " << max_abs_error_ << ")";
1991 }
1992 }
1993 // Restore original precision.
1994 os->precision(old_precision);
1995 }

◆ 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 1956 of file gmock-matchers.h.

1956 {
1957 // os->precision() returns the previously set precision, which we
1958 // store to restore the ostream to its original configuration
1959 // after outputting.
1962 if (FloatingPoint<FloatType>(expected_).is_nan()) {
1963 if (nan_eq_nan_) {
1964 *os << "is NaN";
1965 } else {
1966 *os << "never matches";
1967 }
1968 } else {
1969 *os << "is approximately " << expected_;
1970 if (HasMaxAbsError()) {
1971 *os << " (absolute error <= " << max_abs_error_ << ")";
1972 }
1973 }
1974 os->precision(old_precision);
1975 }

◆ 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 1921 of file gmock-matchers.h.

1922 {
1923 const FloatingPoint<FloatType> actual(value), expected(expected_);
1924
1925 // Compares NaNs first, if nan_eq_nan_ is true.
1926 if (actual.is_nan() || expected.is_nan()) {
1927 if (actual.is_nan() && expected.is_nan()) {
1928 return nan_eq_nan_;
1929 }
1930 // One is nan; the other is not nan.
1931 return false;
1932 }
1933 if (HasMaxAbsError()) {
1934 // We perform an equality check so that inf will match inf, regardless
1935 // of error bounds. If the result of value - expected_ would result in
1936 // overflow or if either value is inf, the default result is infinity,
1937 // which should only match if max_abs_error_ is also infinity.
1938 if (value == expected_) {
1939 return true;
1940 }
1941
1942 const FloatType diff = value - expected_;
1943 if (fabs(diff) <= max_abs_error_) {
1944 return true;
1945 }
1946
1947 if (listener->IsInterested()) {
1948 *listener << "which is " << diff << " from " << expected_;
1949 }
1950 return false;
1951 } else {
1952 return actual.AlmostEquals(expected);
1953 }
1954 }
Here is the call graph for this function:

The documentation for this class was generated from the following file:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/external/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-matchers.h