1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "net/quic/congestion_control/cube_root.h"
7 #include "testing/gtest/include/gtest/gtest.h"
12 class CubeRootTest
: public ::testing::Test
{
18 TEST_F(CubeRootTest
, LowRoot
) {
19 for (uint32 i
= 1; i
< 256; ++i
) {
20 uint64 cube
= i
* i
* i
;
21 uint8 cube_root
= CubeRoot::Root(cube
);
22 EXPECT_EQ(i
, cube_root
);
26 TEST_F(CubeRootTest
, HighRoot
) {
27 // Test the range we will opperate in, 1300 to 130 000.
28 // We expect some loss in accuracy, accepting +-0.2%.
29 for (uint64 i
= 1300; i
< 20000; i
+= 100) {
30 uint64 cube
= i
* i
* i
;
31 uint32 cube_root
= CubeRoot::Root(cube
);
32 uint32 margin
= cube_root
>> 9; // Calculate 0.2% roughly by
34 EXPECT_LE(i
- margin
, cube_root
);
35 EXPECT_GE(i
+ margin
, cube_root
);
37 for (uint64 i
= 20000; i
< 130000; i
*= 2) {
38 uint64 cube
= i
* i
* i
;
39 uint32 cube_root
= CubeRoot::Root(cube
);
40 uint32 margin
= cube_root
>> 9;
41 EXPECT_LE(i
- margin
, cube_root
);
42 EXPECT_GE(i
+ margin
, cube_root
);