| Index: net/quic/test_tools/quic_test_utils.h
|
| diff --git a/net/quic/test_tools/quic_test_utils.h b/net/quic/test_tools/quic_test_utils.h
|
| index ab8226a535d4aa91c20452ec89e8a3c0958a76ba..9d89f9a27a047fb7fc31f6aad0e85960e4649d35 100644
|
| --- a/net/quic/test_tools/quic_test_utils.h
|
| +++ b/net/quic/test_tools/quic_test_utils.h
|
| @@ -1033,6 +1033,22 @@ void CreateServerSessionForTest(
|
| // kClientDataStreamId1 etc. above.
|
| QuicStreamId QuicClientDataStreamId(int i);
|
|
|
| +// Verifies that the relative error of |actual| with respect to |expected| is
|
| +// no more than |margin|.
|
| +
|
| +template <typename T>
|
| +void ExpectApproxEq(T expected, T actual, float relative_margin) {
|
| + // If |relative_margin| > 1 and T is an unsigned type, the comparison will
|
| + // underflow.
|
| + ASSERT_LE(relative_margin, 1);
|
| + ASSERT_GE(relative_margin, 0);
|
| +
|
| + T absolute_margin = expected * relative_margin;
|
| +
|
| + EXPECT_GE(expected + absolute_margin, actual);
|
| + EXPECT_LE(expected - absolute_margin, actual);
|
| +}
|
| +
|
| } // namespace test
|
| } // namespace net
|
|
|
|
|