1 // Copyright 2014 the V8 project 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.
4
5 #include <cmath>
6 #include <limits>
7
8 #include "src/objects.h"
9 #include "src/objects-inl.h"
10
11 #include "src/handles.h"
12 #include "src/handles-inl.h"
13
14 #include "src/heap/heap.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace v8 {
18 namespace internal {
19
Round(double x)20 double Round(double x) {
21 // Round to three digits.
22 return floor(x * 1000 + 0.5) / 1000;
23 }
24
25
CheckEqualRounded(double expected,double actual)26 void CheckEqualRounded(double expected, double actual) {
27 expected = Round(expected);
28 actual = Round(actual);
29 EXPECT_DOUBLE_EQ(expected, actual);
30 }
31
32
TEST(Heap,HeapGrowingFactor)33 TEST(Heap, HeapGrowingFactor) {
34 CheckEqualRounded(Heap::kMaxHeapGrowingFactor,
35 Heap::HeapGrowingFactor(34, 1));
36 CheckEqualRounded(3.553, Heap::HeapGrowingFactor(45, 1));
37 CheckEqualRounded(2.830, Heap::HeapGrowingFactor(50, 1));
38 CheckEqualRounded(1.478, Heap::HeapGrowingFactor(100, 1));
39 CheckEqualRounded(1.193, Heap::HeapGrowingFactor(200, 1));
40 CheckEqualRounded(1.121, Heap::HeapGrowingFactor(300, 1));
41 CheckEqualRounded(Heap::HeapGrowingFactor(300, 1),
42 Heap::HeapGrowingFactor(600, 2));
43 CheckEqualRounded(Heap::kMinHeapGrowingFactor,
44 Heap::HeapGrowingFactor(400, 1));
45 }
46
47 } // namespace internal
48 } // namespace v8
49