1 /*
 2  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
 3  * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
 4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 5  *
 6  * This code is free software; you can redistribute it and/or modify it
 7  * under the terms of the GNU General Public License version 2 only, as
 8  * published by the Free Software Foundation.
 9  *
10  * This code is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * version 2 for more details (a copy is included in the LICENSE file that
14  * accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License version
17  * 2 along with this work; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21  * or visit www.oracle.com if you need additional information or have any
22  * questions.
23  */
24 
25 #include "precompiled.hpp"
26 #include "gc/shenandoah/shenandoahNumberSeq.hpp"
27 #include "utilities/ostream.hpp"
28 
29 #include "utilities/vmassert_uninstall.hpp"
30 #include <iostream>
31 #include "utilities/vmassert_reinstall.hpp"
32 
33 #include "unittest.hpp"
34 
35 class ShenandoahNumberSeqTest: public ::testing::Test {
36  protected:
37   HdrSeq seq;
38 };
39 
40 class BasicShenandoahNumberSeqTest: public ShenandoahNumberSeqTest {
41  protected:
42   const double err = 0.5;
43   BasicShenandoahNumberSeqTest() {
44     seq.add(0);
45     seq.add(1);
46     seq.add(10);
47     for (int i = 0; i < 7; i++) {
48       seq.add(100);
49     }
50     std::cout << " p0 = " << seq.percentile(0);
51     std::cout << " p10 = " << seq.percentile(10);
52     std::cout << " p20 = " << seq.percentile(20);
53     std::cout << " p30 = " << seq.percentile(30);
54     std::cout << " p50 = " << seq.percentile(50);
55     std::cout << " p80 = " << seq.percentile(80);
56     std::cout << " p90 = " << seq.percentile(90);
57     std::cout << " p100 = " << seq.percentile(100);
58   }
59 };
60 
61 TEST_VM_F(BasicShenandoahNumberSeqTest, maximum_test) {
62   EXPECT_EQ(seq.maximum(), 100);
63 }
64 
65 TEST_VM_F(BasicShenandoahNumberSeqTest, minimum_test) {
66   EXPECT_EQ(0, seq.percentile(0));
67 }
68 
69 TEST_VM_F(BasicShenandoahNumberSeqTest, percentile_test) {
70   EXPECT_NEAR(0, seq.percentile(10), err);
71   EXPECT_NEAR(1, seq.percentile(20), err);
72   EXPECT_NEAR(10, seq.percentile(30), err);
73   EXPECT_NEAR(100, seq.percentile(40), err);
74   EXPECT_NEAR(100, seq.percentile(50), err);
75   EXPECT_NEAR(100, seq.percentile(75), err);
76   EXPECT_NEAR(100, seq.percentile(90), err);
77   EXPECT_NEAR(100, seq.percentile(100), err);
78 }