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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Common utilities for Quic tests 5 // Common utilities for Quic tests
6 6
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 MockAlarmFactory* alarm_factory, 1026 MockAlarmFactory* alarm_factory,
1027 QuicCryptoServerConfig* crypto_server_config, 1027 QuicCryptoServerConfig* crypto_server_config,
1028 QuicCompressedCertsCache* compressed_certs_cache, 1028 QuicCompressedCertsCache* compressed_certs_cache,
1029 PacketSavingConnection** server_connection, 1029 PacketSavingConnection** server_connection,
1030 TestQuicSpdyServerSession** server_session); 1030 TestQuicSpdyServerSession** server_session);
1031 1031
1032 // Helper to generate client side stream ids, generalizes 1032 // Helper to generate client side stream ids, generalizes
1033 // kClientDataStreamId1 etc. above. 1033 // kClientDataStreamId1 etc. above.
1034 QuicStreamId QuicClientDataStreamId(int i); 1034 QuicStreamId QuicClientDataStreamId(int i);
1035 1035
1036 // Verifies that the relative error of |actual| with respect to |expected| is
1037 // no more than |margin|.
1038
1039 template <typename T>
1040 void ExpectApproxEq(T expected, T actual, float relative_margin) {
1041 // If |relative_margin| > 1 and T is an unsigned type, the comparison will
1042 // underflow.
1043 ASSERT_LE(relative_margin, 1);
1044 ASSERT_GE(relative_margin, 0);
1045
1046 T absolute_margin = expected * relative_margin;
1047
1048 EXPECT_GE(expected + absolute_margin, actual);
1049 EXPECT_LE(expected - absolute_margin, actual);
1050 }
1051
1036 } // namespace test 1052 } // namespace test
1037 } // namespace net 1053 } // namespace net
1038 1054
1039 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 1055 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW
« 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