proxygen
testing::internal::FloatingEqMatcher< FloatType >::Impl< T > Class Template Reference

#include <gmock-matchers.h>

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

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

Private Member Functions

bool HasMaxAbsError () const
 
 GTEST_DISALLOW_ASSIGN_ (Impl)
 
bool HasMaxAbsError () const
 
 GTEST_DISALLOW_ASSIGN_ (Impl)
 
bool HasMaxAbsError () const
 
 GTEST_DISALLOW_ASSIGN_ (Impl)
 

Private Attributes

const FloatType expected_
 
const bool nan_eq_nan_
 
const FloatType max_abs_error_
 

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

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) {}
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) {}
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

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.

References folly::digits10().

1977  {
1978  // As before, get original precision.
1979  const ::std::streamsize old_precision = os->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  }
uint32_t digits10(uint64_t v)
Definition: Conv.h:295
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.

References folly::digits10().

1977  {
1978  // As before, get original precision.
1979  const ::std::streamsize old_precision = os->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  }
uint32_t digits10(uint64_t v)
Definition: Conv.h:295
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.

References folly::digits10().

1977  {
1978  // As before, get original precision.
1979  const ::std::streamsize old_precision = os->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  }
uint32_t digits10(uint64_t v)
Definition: Conv.h:295
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.

References folly::digits10().

1956  {
1957  // os->precision() returns the previously set precision, which we
1958  // store to restore the ostream to its original configuration
1959  // after outputting.
1960  const ::std::streamsize old_precision = os->precision(
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  }
uint32_t digits10(uint64_t v)
Definition: Conv.h:295
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.

References folly::digits10().

1956  {
1957  // os->precision() returns the previously set precision, which we
1958  // store to restore the ostream to its original configuration
1959  // after outputting.
1960  const ::std::streamsize old_precision = os->precision(
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  }
uint32_t digits10(uint64_t v)
Definition: Conv.h:295
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.

References folly::digits10().

1956  {
1957  // os->precision() returns the previously set precision, which we
1958  // store to restore the ostream to its original configuration
1959  // after outputting.
1960  const ::std::streamsize old_precision = os->precision(
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  }
uint32_t digits10(uint64_t v)
Definition: Conv.h:295
template<typename FloatType>
template<typename T >
testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::GTEST_DISALLOW_ASSIGN_ ( Impl< T )
private
template<typename FloatType>
template<typename T >
testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::GTEST_DISALLOW_ASSIGN_ ( Impl< T )
private
template<typename FloatType>
template<typename T >
testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::GTEST_DISALLOW_ASSIGN_ ( Impl< T )
private
template<typename FloatType>
template<typename T >
bool testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::HasMaxAbsError ( ) const
inlineprivate

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

1998  {
1999  return max_abs_error_ >= 0;
2000  }
template<typename FloatType>
template<typename T >
bool testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::HasMaxAbsError ( ) const
inlineprivate

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

References GTEST_DISALLOW_ASSIGN_.

1998  {
1999  return max_abs_error_ >= 0;
2000  }
template<typename FloatType>
template<typename T >
bool testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::HasMaxAbsError ( ) const
inlineprivate

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

References GTEST_DISALLOW_ASSIGN_.

1998  {
1999  return max_abs_error_ >= 0;
2000  }
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.

References diff(), testing::internal::FloatingPoint< RawType >::is_nan(), and testing::MatchResultListener::IsInterested().

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  }
static const char *const value
Definition: Conv.cpp:50
uint64_t diff(uint64_t a, uint64_t b)
Definition: FutexTest.cpp:135
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.

References diff(), and testing::internal::FloatingPoint< RawType >::is_nan().

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  }
static const char *const value
Definition: Conv.cpp:50
uint64_t diff(uint64_t a, uint64_t b)
Definition: FutexTest.cpp:135
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.

References diff(), and testing::internal::FloatingPoint< RawType >::is_nan().

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  }
static const char *const value
Definition: Conv.cpp:50
uint64_t diff(uint64_t a, uint64_t b)
Definition: FutexTest.cpp:135

Member Data Documentation

template<typename FloatType>
template<typename T >
const FloatType testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::expected_
private

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

template<typename FloatType>
template<typename T >
const FloatType testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::max_abs_error_
private

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

template<typename FloatType>
template<typename T >
const bool testing::internal::FloatingEqMatcher< FloatType >::Impl< T >::nan_eq_nan_
private

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


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