Zhanyong Wan 0bdccf4aa2 Add a DistanceFrom() matcher for general distance comparison.
We have a bunch of matchers for asserting that a value is near the target value, e.g.
`DoubleNear()` and `FloatNear()`. These matchers only work for specific types (`double` and `float`). They are not flexible enough to support other types that have the notion of a "distance" (e.g. N-dimensional points and vectors, which are commonly used in ML).

In this diff, we generalize the idea to a `DistanceFrom(target, get_distance, m)` matcher that works on arbitrary types that have the "distance" concept (the `get_distance` argument is optional and can be omitted for types that support `-`, and `std::abs()`). What it does:

1. compute the distance between the value and the target using `get_distance(value, target)`; if `get_distance` is omitted, compute the distance as `std::abs(value - target)`.
2. match the distance against matcher `m`; if the match succeeds, the `DistanceFrom()` match succeeds.

Examples:

```
  // 0.5's distance from 0.6 should be <= 0.2.
  EXPECT_THAT(0.5, DistanceFrom(0.6, Le(0.2)));

  Vector2D v1(3.0, 4.0), v2(3.2, 6.0);
  // v1's distance from v2, as computed by EuclideanDistance(v1, v2),
  // should be >= 1.0.
  EXPECT_THAT(v1, DistanceFrom(v2, EuclideanDistance, Ge(1.0)));
```

PiperOrigin-RevId: 734593292
Change-Id: Id6bb7074dc4aa4d8abd78b57ad2426637e590de5
2025-03-07 09:54:00 -08:00
..
_data Googletest export 2021-06-02 17:55:09 -04:00
_layouts documentation, change mater branch to main 2022-06-22 14:36:10 +03:00
_sass Googletest export 2021-05-25 13:34:39 -04:00
assets/css Googletest export 2021-02-19 13:55:48 -05:00
reference Add a DistanceFrom() matcher for general distance comparison. 2025-03-07 09:54:00 -08:00
_config.yml Googletest export 2021-02-19 13:55:48 -05:00
advanced.md Adds support for a --gtest_fail_if_no_test_linked flag 2025-02-24 13:18:33 -08:00
community_created_documentation.md Googletest export 2021-01-15 15:54:03 -05:00
faq.md GoogleTest FAQ: minor punctuation fixes 2023-09-14 10:37:04 -07:00
gmock_cheat_sheet.md Adjust includes to use <> instead of "", consistent with quickstart pages. 2023-07-28 09:51:41 -07:00
gmock_cook_book.md Enable safe matcher casts from Matcher<const T&> to Matcher<T>. 2025-01-15 09:16:57 -08:00
gmock_faq.md Fix reference to source file in gmock FAQ 2022-01-14 14:40:35 -08:00
gmock_for_dummies.md Add anchor for expectation ordering note 2024-02-13 13:55:04 -08:00
index.md Googletest export 2021-02-26 17:58:04 -05:00
pkgconfig.md cmake: Raise min to 3.6 2023-06-19 11:21:44 -06:00
platforms.md Copy supported platforms from README onto https://google.github.io/googletest/platforms.html 2023-06-01 07:28:42 -07:00
primer.md Update the links to ISTQB glossary. 2024-12-11 08:00:11 -08:00
quickstart-bazel.md Update main to point to 1.15.2 patch release 2024-08-01 06:34:56 -07:00
quickstart-cmake.md Add CXX_STANDARD_REQUIRED to CMake quickstart 2023-05-21 16:40:06 -07:00
samples.md Merge pull request #3918 from assafpr:master2main 2022-08-01 11:47:51 -07:00