Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/util/DoubleSummaryStatistics/NegativeCompensation.java
66644 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8214761
27
* @run testng NegativeCompensation
28
* @summary When combining two DoubleSummaryStatistics, the compensation
29
* has to be subtracted.
30
*/
31
32
import java.util.DoubleSummaryStatistics;
33
import org.testng.annotations.Test;
34
import static org.testng.Assert.assertEquals;
35
import static org.testng.Assert.assertTrue;
36
37
public class NegativeCompensation {
38
static final double VAL = 1.000000001;
39
static final int LOG_ITER = 21;
40
41
@Test
42
public static void testErrorComparision() {
43
DoubleSummaryStatistics stat0 = new DoubleSummaryStatistics();
44
DoubleSummaryStatistics stat1 = new DoubleSummaryStatistics();
45
DoubleSummaryStatistics stat2 = new DoubleSummaryStatistics();
46
47
stat1.accept(VAL);
48
stat1.accept(VAL);
49
stat2.accept(VAL);
50
stat2.accept(VAL);
51
stat2.accept(VAL);
52
53
for (int i = 0; i < LOG_ITER; ++i) {
54
stat1.combine(stat2);
55
stat2.combine(stat1);
56
}
57
58
for (long i = 0, iend = stat2.getCount(); i < iend; ++i) {
59
stat0.accept(VAL);
60
}
61
62
double res = 0;
63
for(long i = 0, iend = stat2.getCount(); i < iend; ++i) {
64
res += VAL;
65
}
66
67
double absErrN = Math.abs(res - stat2.getSum());
68
double absErr = Math.abs(stat0.getSum() - stat2.getSum());
69
assertTrue(absErrN >= absErr,
70
"Naive sum error is not greater than or equal to Summary sum");
71
assertEquals(absErr, 0.0, "Absolute error is not zero");
72
}
73
}
74