|
| 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 <iostream> |
| 28 | +#include "unittest.hpp" |
| 29 | +#include "utilities/ostream.hpp" |
| 30 | + |
| 31 | +class ShenandoahNumberSeqTest: public ::testing::Test { |
| 32 | + protected: |
| 33 | + HdrSeq seq; |
| 34 | +}; |
| 35 | + |
| 36 | +class BasicShenandoahNumberSeqTest: public ShenandoahNumberSeqTest { |
| 37 | + protected: |
| 38 | + const double err = 0.5; |
| 39 | + BasicShenandoahNumberSeqTest() { |
| 40 | + seq.add(0); |
| 41 | + seq.add(1); |
| 42 | + seq.add(10); |
| 43 | + for (int i = 0; i < 7; i++) { |
| 44 | + seq.add(100); |
| 45 | + } |
| 46 | + std::cout << " p0 = " << seq.percentile(0); |
| 47 | + std::cout << " p10 = " << seq.percentile(10); |
| 48 | + std::cout << " p20 = " << seq.percentile(20); |
| 49 | + std::cout << " p30 = " << seq.percentile(30); |
| 50 | + std::cout << " p50 = " << seq.percentile(50); |
| 51 | + std::cout << " p80 = " << seq.percentile(80); |
| 52 | + std::cout << " p90 = " << seq.percentile(90); |
| 53 | + std::cout << " p100 = " << seq.percentile(100); |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | +TEST_VM_F(BasicShenandoahNumberSeqTest, maximum_test) { |
| 58 | + EXPECT_EQ(seq.maximum(), 100); |
| 59 | +} |
| 60 | + |
| 61 | +TEST_VM_F(BasicShenandoahNumberSeqTest, minimum_test) { |
| 62 | + EXPECT_EQ(0, seq.percentile(0)); |
| 63 | +} |
| 64 | + |
| 65 | +TEST_VM_F(BasicShenandoahNumberSeqTest, percentile_test) { |
| 66 | + EXPECT_NEAR(0, seq.percentile(10), err); |
| 67 | + EXPECT_NEAR(1, seq.percentile(20), err); |
| 68 | + EXPECT_NEAR(10, seq.percentile(30), err); |
| 69 | + EXPECT_NEAR(100, seq.percentile(40), err); |
| 70 | + EXPECT_NEAR(100, seq.percentile(50), err); |
| 71 | + EXPECT_NEAR(100, seq.percentile(75), err); |
| 72 | + EXPECT_NEAR(100, seq.percentile(90), err); |
| 73 | + EXPECT_NEAR(100, seq.percentile(100), err); |
| 74 | +} |
0 commit comments