Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Random/RandomTestCoverage.java
41149 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
import java.math.BigInteger;
25
import java.security.SecureRandom;
26
import java.util.concurrent.ThreadLocalRandom;
27
import java.util.random.RandomGenerator;
28
import java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator;
29
import java.util.random.RandomGenerator.JumpableGenerator;
30
import java.util.random.RandomGenerator.LeapableGenerator;
31
import java.util.random.RandomGenerator.SplittableGenerator;
32
import java.util.random.RandomGenerator.StreamableGenerator;
33
import java.util.random.RandomGeneratorFactory;
34
import java.util.stream.DoubleStream;
35
import java.util.stream.IntStream;
36
import java.util.stream.LongStream;
37
import java.util.stream.Stream;
38
39
/**
40
* @test
41
* @summary Ensure that all implementations of RandomGenerator supply required methods.
42
* @bug 8248862
43
* @run main RandomTestCoverage
44
* @key randomness
45
*/
46
47
48
public class RandomTestCoverage {
49
static void coverRandomGenerator(RandomGenerator rng) {
50
boolean bool = rng.nextBoolean();
51
byte[] bytes = new byte[8];
52
rng.nextBytes(bytes);
53
54
int i1 = rng.nextInt();
55
int i2 = rng.nextInt(10);
56
int i3 = rng.nextInt(5, 10);
57
58
long l1 = rng.nextLong();
59
long l2 = rng.nextLong(10L);
60
long l3 = rng.nextLong(5L, 10L);
61
62
float f1 = rng.nextFloat();
63
float f2 = rng.nextFloat(1.0f);
64
float f3 = rng.nextFloat(0.5f, 1.0f);
65
66
double d1 = rng.nextDouble();
67
double d2 = rng.nextDouble(1.0);
68
double d3 = rng.nextDouble(0.5, 1.0);
69
70
double exp = rng.nextExponential();
71
double gauss1 = rng.nextGaussian();
72
double gauss2 = rng.nextGaussian(0.5, 2.0);
73
74
IntStream intStream1 = rng.ints();
75
IntStream intStream2 = rng.ints(5, 10);
76
IntStream intStream3 = rng.ints(5L);
77
IntStream intStream4 = rng.ints(5L, 5, 10);
78
79
LongStream longStream1 = rng.longs();
80
LongStream longStream2 = rng.longs(5L, 10L);
81
LongStream longStream3 = rng.longs(5L);
82
LongStream longStream4 = rng.longs(5L, 5L, 10L);
83
84
DoubleStream doubleStream1 = rng.doubles();
85
DoubleStream doubleStream2 = rng.doubles(0.5, 1.0);
86
DoubleStream doubleStream3 = rng.doubles(5);
87
DoubleStream doubleStream4 = rng.doubles(5, 0.5, 1.0);
88
}
89
90
static void checkPredicates(RandomGeneratorFactory factory) {
91
RandomGenerator rng = factory.create();
92
if (rng instanceof ArbitrarilyJumpableGenerator != factory.isArbitrarilyJumpable()) {
93
throw new RuntimeException("isArbitrarilyJumpable failing");
94
}
95
if (rng instanceof JumpableGenerator != factory.isJumpable()) {
96
throw new RuntimeException("isJumpable failing");
97
}
98
if (rng instanceof LeapableGenerator != factory.isLeapable()) {
99
throw new RuntimeException("isLeapable failing");
100
}
101
if (rng instanceof SplittableGenerator != factory.isSplittable()) {
102
throw new RuntimeException("isArbitrarilyJumpable failing");
103
}
104
if (rng instanceof StreamableGenerator != factory.isStreamable()) {
105
throw new RuntimeException("isArbitrarilyJumpable failing");
106
}
107
}
108
109
static void coverStreamable(StreamableGenerator rng) {
110
Stream<RandomGenerator> rngs1 = rng.rngs();
111
Stream<RandomGenerator> rngs2 = rng.rngs(5L);
112
}
113
114
static void coverSplittable(SplittableGenerator rng) {
115
SplittableGenerator s1 = rng.split();
116
SplittableGenerator s2 = rng.split(rng);
117
Stream<SplittableGenerator> s3 = rng.splits();
118
Stream<SplittableGenerator> s4 = rng.splits(5L);
119
Stream<SplittableGenerator> s5 = rng.splits(rng);
120
Stream<SplittableGenerator> s6 = rng.splits(5L, rng);
121
}
122
123
static void coverJumpable(JumpableGenerator rng) {
124
JumpableGenerator j1 = rng.copy();
125
rng.jump();
126
RandomGenerator j2 = rng.copyAndJump();
127
double d = rng.jumpDistance();
128
Stream<RandomGenerator> j3 = rng.jumps();
129
Stream<RandomGenerator> j4 = rng.jumps(5L);
130
}
131
132
static void coverLeapable(LeapableGenerator rng) {
133
LeapableGenerator l1 = rng.copy();
134
rng.leap();
135
JumpableGenerator l2 = rng.copyAndLeap();
136
double d = rng.leapDistance();
137
Stream<JumpableGenerator> l3 = rng.leaps();
138
Stream<JumpableGenerator> l4 = rng.leaps(5L);
139
}
140
141
static void coverArbitrarilyJumpable(ArbitrarilyJumpableGenerator rng) {
142
ArbitrarilyJumpableGenerator a1 = rng.copy();
143
rng.jump();
144
rng.leap();
145
rng.jump(1.2345);
146
rng.jumpPowerOfTwo(4);
147
RandomGenerator a2 = rng.copyAndJump();
148
RandomGenerator a3 = rng.copyAndJump(1.2345);
149
Stream<ArbitrarilyJumpableGenerator> a4 = rng.jumps(1.2345);
150
Stream<ArbitrarilyJumpableGenerator> a5 = rng.jumps(5L, 1.2345);
151
152
}
153
154
static void coverOf(String name) {
155
coverRandomGenerator(RandomGenerator.of(name));
156
coverFactory(RandomGeneratorFactory.of(name));
157
}
158
159
static void coverFactory(RandomGeneratorFactory factory) {
160
String name = factory.name();
161
String group = factory.group();
162
int stateBits = factory.stateBits();
163
int equidistribution = factory.equidistribution();
164
BigInteger period = factory.period();
165
boolean isStatistical = factory.isStatistical();
166
boolean isStochastic = factory.isStochastic();
167
boolean isHardware = factory.isHardware();
168
boolean isArbitrarilyJumpable = factory.isArbitrarilyJumpable();
169
boolean isJumpable = factory.isJumpable();
170
boolean isLeapable = factory.isLeapable();
171
boolean isSplittable = factory.isSplittable();
172
173
coverRandomGenerator(factory.create());
174
coverRandomGenerator(factory.create(12345L));
175
coverRandomGenerator(factory.create(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}));
176
}
177
178
static void coverDefaults() {
179
RandomGeneratorFactory<RandomGenerator> factory =
180
RandomGeneratorFactory.getDefault();
181
RandomGenerator rng = RandomGenerator.getDefault();
182
}
183
184
public static void main(String[] args) throws Throwable {
185
RandomGeneratorFactory.all()
186
.forEach(factory -> {
187
coverFactory(factory);
188
coverOf(factory.name());
189
});
190
RandomGeneratorFactory.all()
191
.filter(f -> f.isStreamable())
192
.forEach(factory -> {
193
coverStreamable((StreamableGenerator)factory.create());
194
});
195
RandomGeneratorFactory.all()
196
.filter(f -> f.isSplittable())
197
.forEach(factory -> {
198
coverSplittable((SplittableGenerator)factory.create());
199
});
200
RandomGeneratorFactory.all()
201
.filter(f -> f.isJumpable())
202
.forEach(factory -> {
203
coverJumpable((JumpableGenerator)factory.create());
204
});
205
RandomGeneratorFactory.all()
206
.filter(f -> f.isLeapable())
207
.forEach(factory -> {
208
coverLeapable((LeapableGenerator)factory.create());
209
});
210
RandomGeneratorFactory.all()
211
.filter(f -> f.isArbitrarilyJumpable())
212
.forEach(factory -> {
213
coverArbitrarilyJumpable((ArbitrarilyJumpableGenerator)factory.create());
214
});
215
216
coverRandomGenerator(new SecureRandom());
217
coverRandomGenerator(ThreadLocalRandom.current());
218
}
219
}
220
221