mirror of
https://github.com/google/googletest.git
synced 2025-12-06 16:57:00 +08:00
FloatingEqMatcher supports conversion to const float types
This commit is contained in:
parent
b75ecf1bed
commit
8ffc42998b
@ -1761,9 +1761,15 @@ class FloatingEqMatcher {
|
|||||||
const FloatType max_abs_error_;
|
const FloatType max_abs_error_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The following 3 type conversion operators allow FloatEq(expected) and
|
// The following 4 type conversion operators allow FloatEq(expected) and
|
||||||
// NanSensitiveFloatEq(expected) to be used as a Matcher<float>, a
|
// NanSensitiveFloatEq(expected) to be used as a Matcher<const float>,
|
||||||
// Matcher<const float&>, or a Matcher<float&>, but nothing else.
|
// a Matcher<float>, a Matcher<const float&>, or a Matcher<float&>,
|
||||||
|
// but nothing else.
|
||||||
|
operator Matcher<const FloatType>() const {
|
||||||
|
return MakeMatcher(
|
||||||
|
new Impl<const FloatType>(expected_, nan_eq_nan_, max_abs_error_));
|
||||||
|
}
|
||||||
|
|
||||||
operator Matcher<FloatType>() const {
|
operator Matcher<FloatType>() const {
|
||||||
return MakeMatcher(
|
return MakeMatcher(
|
||||||
new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
|
new Impl<FloatType>(expected_, nan_eq_nan_, max_abs_error_));
|
||||||
|
|||||||
@ -696,6 +696,11 @@ TEST(OptionalTest, DescribesSelf) {
|
|||||||
EXPECT_EQ("value is equal to 1", Describe(m));
|
EXPECT_EQ("value is equal to 1", Describe(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(OptionalTest, WorksWithConstDouble) {
|
||||||
|
const SampleOptional<const double> opt(3.14159);
|
||||||
|
EXPECT_THAT(opt, Optional(DoubleEq(3.14159)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(OptionalTest, ExplainsSelf) {
|
TEST(OptionalTest, ExplainsSelf) {
|
||||||
const Matcher<SampleOptional<int>> m = Optional(Eq(1));
|
const Matcher<SampleOptional<int>> m = Optional(Eq(1));
|
||||||
EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptional<int>(1)));
|
EXPECT_EQ("whose value 1 matches", Explain(m, SampleOptional<int>(1)));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user