@@ -38,6 +38,37 @@ MATCHER_P(IsProtoEqual, value, "Checks whether protos are equal") {
3838 return !delta.has_value ();
3939}
4040
41+ // Compares float and double fields approximately, using the default
42+ // google::protobuf::MessageDifferencer tolerances.
43+ absl::optional<std::string> CompareProtosApproximately (
44+ google::protobuf::Message const & arg,
45+ google::protobuf::Message const & value);
46+
47+ MATCHER_P (IsProtoApproximatelyEqual, value,
48+ " Checks whether protos are approximately equal" ) {
49+ absl::optional<std::string> delta = CompareProtosApproximately (arg, value);
50+ if (delta.has_value ()) {
51+ *result_listener << " \n " << *delta;
52+ }
53+ return !delta.has_value ();
54+ }
55+
56+ // Compares float and double fields approximately, using the given
57+ // @p fraction and @p margin.
58+ absl::optional<std::string> CompareProtosApproximately (
59+ google::protobuf::Message const & arg,
60+ google::protobuf::Message const & value, double fraction, double margin);
61+
62+ MATCHER_P3 (IsProtoApproximatelyEqual, value, fraction, margin,
63+ " Checks whether protos are approximately equal" ) {
64+ absl::optional<std::string> delta =
65+ CompareProtosApproximately (arg, value, fraction, margin);
66+ if (delta.has_value ()) {
67+ *result_listener << " \n " << *delta;
68+ }
69+ return !delta.has_value ();
70+ }
71+
4172} // namespace testing_util
4273GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
4374} // namespace cloud
0 commit comments