From bbe4b7363bbaa7c9e07dbacde11602a4c69504d3 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 17 Oct 2019 12:50:10 -0400 Subject: Googletest export Added IsNan matcher PiperOrigin-RevId: 275278634 --- googlemock/test/gmock-matchers_test.cc | 108 +++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'googlemock/test') diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 03735267..45141750 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -2054,6 +2054,114 @@ TEST(PairMatchBaseTest, WorksWithMoveOnly) { EXPECT_TRUE(matcher.Matches(pointers)); } +// Tests that IsNan() matches a NaN, with float. +TEST(IsNan, FloatMatchesNan) { + float quiet_nan = std::numeric_limits::quiet_NaN(); + float other_nan = std::nan("1"); + float real_value = 1.0f; + + Matcher m = IsNan(); + EXPECT_TRUE(m.Matches(quiet_nan)); + EXPECT_TRUE(m.Matches(other_nan)); + EXPECT_FALSE(m.Matches(real_value)); + + Matcher m_ref = IsNan(); + EXPECT_TRUE(m_ref.Matches(quiet_nan)); + EXPECT_TRUE(m_ref.Matches(other_nan)); + EXPECT_FALSE(m_ref.Matches(real_value)); + + Matcher m_cref = IsNan(); + EXPECT_TRUE(m_cref.Matches(quiet_nan)); + EXPECT_TRUE(m_cref.Matches(other_nan)); + EXPECT_FALSE(m_cref.Matches(real_value)); +} + +// Tests that IsNan() matches a NaN, with double. +TEST(IsNan, DoubleMatchesNan) { + double quiet_nan = std::numeric_limits::quiet_NaN(); + double other_nan = std::nan("1"); + double real_value = 1.0; + + Matcher m = IsNan(); + EXPECT_TRUE(m.Matches(quiet_nan)); + EXPECT_TRUE(m.Matches(other_nan)); + EXPECT_FALSE(m.Matches(real_value)); + + Matcher m_ref = IsNan(); + EXPECT_TRUE(m_ref.Matches(quiet_nan)); + EXPECT_TRUE(m_ref.Matches(other_nan)); + EXPECT_FALSE(m_ref.Matches(real_value)); + + Matcher m_cref = IsNan(); + EXPECT_TRUE(m_cref.Matches(quiet_nan)); + EXPECT_TRUE(m_cref.Matches(other_nan)); + EXPECT_FALSE(m_cref.Matches(real_value)); +} + +// Tests that IsNan() matches a NaN, with long double. +TEST(IsNan, LongDoubleMatchesNan) { + long double quiet_nan = std::numeric_limits::quiet_NaN(); + long double other_nan = std::nan("1"); + long double real_value = 1.0; + + Matcher m = IsNan(); + EXPECT_TRUE(m.Matches(quiet_nan)); + EXPECT_TRUE(m.Matches(other_nan)); + EXPECT_FALSE(m.Matches(real_value)); + + Matcher m_ref = IsNan(); + EXPECT_TRUE(m_ref.Matches(quiet_nan)); + EXPECT_TRUE(m_ref.Matches(other_nan)); + EXPECT_FALSE(m_ref.Matches(real_value)); + + Matcher m_cref = IsNan(); + EXPECT_TRUE(m_cref.Matches(quiet_nan)); + EXPECT_TRUE(m_cref.Matches(other_nan)); + EXPECT_FALSE(m_cref.Matches(real_value)); +} + +// Tests that IsNan() works with Not. +TEST(IsNan, NotMatchesNan) { + Matcher mf = Not(IsNan()); + EXPECT_FALSE(mf.Matches(std::numeric_limits::quiet_NaN())); + EXPECT_FALSE(mf.Matches(std::nan("1"))); + EXPECT_TRUE(mf.Matches(1.0)); + + Matcher md = Not(IsNan()); + EXPECT_FALSE(md.Matches(std::numeric_limits::quiet_NaN())); + EXPECT_FALSE(md.Matches(std::nan("1"))); + EXPECT_TRUE(md.Matches(1.0)); + + Matcher mld = Not(IsNan()); + EXPECT_FALSE(mld.Matches(std::numeric_limits::quiet_NaN())); + EXPECT_FALSE(mld.Matches(std::nan("1"))); + EXPECT_TRUE(mld.Matches(1.0)); +} + +// Tests that IsNan() can describe itself. +TEST(IsNan, CanDescribeSelf) { + Matcher mf = IsNan(); + EXPECT_EQ("is NaN", Describe(mf)); + + Matcher md = IsNan(); + EXPECT_EQ("is NaN", Describe(md)); + + Matcher mld = IsNan(); + EXPECT_EQ("is NaN", Describe(mld)); +} + +// Tests that IsNan() can describe itself with Not. +TEST(IsNan, CanDescribeSelfWithNot) { + Matcher mf = Not(IsNan()); + EXPECT_EQ("isn't NaN", Describe(mf)); + + Matcher md = Not(IsNan()); + EXPECT_EQ("isn't NaN", Describe(md)); + + Matcher mld = Not(IsNan()); + EXPECT_EQ("isn't NaN", Describe(mld)); +} + // Tests that FloatEq() matches a 2-tuple where // FloatEq(first field) matches the second field. TEST(FloatEq2Test, MatchesEqualArguments) { -- cgit v1.2.3