Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: net/quic/test_tools/quic_test_utils.h

Issue 2336913006: Introduce ExpectApproxEq, a helper function that allows making assertions that certain values are e… (Closed)
Patch Set: Fix MSVC warnings Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « net/quic/core/congestion_control/simulation/simulator_test.cc ('k') | net/quic/test_tools/quic_test_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698