Skip to content

Commit acbae8e

Browse files
committed
update Java version
1 parent 14322ea commit acbae8e

File tree

1 file changed

+1
-192
lines changed

1 file changed

+1
-192
lines changed

src/test/java/com/upokecenter/test/RandomObjects.java

+1-192
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ public static byte[] RandomByteStringShort(IRandomGenExtended rand) {
116116
rand.GetInt32(MaxExclusiveShortStringLength));
117117
}
118118

119-
public static ERational RandomERational(IRandomGenExtended rand) {
120-
EInteger bigintA = RandomEInteger(rand);
121-
EInteger bigintB = RandomEInteger(rand);
122-
if (bigintB.isZero()) {
123-
bigintB = EInteger.FromInt32(1);
124-
}
125-
return ERational.Create(bigintA, bigintB);
126-
}
127-
128119
public static String RandomTextString(IRandomGenExtended rand) {
129120
if (rand == null) {
130121
throw new NullPointerException("rand");
@@ -262,188 +253,6 @@ public static String RandomDecimalStringShort(
262253
return sb.toString();
263254
}
264255

265-
public static EDecimal GenerateEDecimalSmall(IRandomGenExtended wrapper) {
266-
if (wrapper == null) {
267-
throw new NullPointerException("wrapper");
268-
}
269-
if (wrapper.GetInt32(2) == 0) {
270-
EInteger eix = EInteger.FromBytes(
271-
RandomByteString(wrapper, 1 + wrapper.GetInt32(36)),
272-
true);
273-
int exp = wrapper.GetInt32(25) - 12;
274-
return EDecimal.Create(eix, exp);
275-
}
276-
return EDecimal.FromString(RandomDecimalStringShort(wrapper, false));
277-
}
278-
279-
public static EDecimal RandomEDecimal(IRandomGenExtended r) {
280-
return RandomEDecimal(r, null);
281-
}
282-
283-
public static EDecimal RandomEDecimal(IRandomGenExtended r, String[]
284-
decimalString) {
285-
if (r == null) {
286-
throw new NullPointerException("r");
287-
}
288-
if (r.GetInt32(100) == 0) {
289-
int x = r.GetInt32(3);
290-
if (x == 0) {
291-
if (decimalString != null) {
292-
decimalString[0] = "Infinity";
293-
}
294-
return EDecimal.PositiveInfinity;
295-
}
296-
if (x == 1) {
297-
if (decimalString != null) {
298-
decimalString[0] = "-Infinity";
299-
}
300-
return EDecimal.NegativeInfinity;
301-
}
302-
if (x == 2) {
303-
if (decimalString != null) {
304-
decimalString[0] = "NaN";
305-
}
306-
return EDecimal.NaN;
307-
}
308-
// Signaling NaN currently not generated because
309-
// it doesn't round-trip as well
310-
}
311-
if (r.GetInt32(100) < 30) {
312-
String str = RandomDecimalString(r);
313-
if (str.length() < 500) {
314-
if (decimalString != null) {
315-
decimalString[0] = str;
316-
}
317-
return EDecimal.FromString(str);
318-
}
319-
}
320-
EInteger emant = RandomEInteger(r);
321-
EInteger eexp;
322-
if (r.GetInt32(100) < 95) {
323-
int exp = (r.GetInt32(100) < 80) ? (r.GetInt32(50) - 25) :
324-
(r.GetInt32(5000) - 2500);
325-
eexp = EInteger.FromInt32(exp);
326-
} else {
327-
eexp = RandomEInteger(r);
328-
}
329-
EDecimal ed = EDecimal.Create(emant, eexp);
330-
if (decimalString != null) {
331-
decimalString[0] = emant.toString() + "E" + eexp.toString();
332-
}
333-
return ed;
334-
}
335-
336-
private static EInteger BitHeavyEInteger(IRandomGenExtended rg, int count) {
337-
StringBuilder sb = new StringBuilder();
338-
int[] oneChances = {
339-
999, 1, 980, 20, 750, 250, 980,
340-
20, 980, 20, 980, 20, 750, 250,
341-
};
342-
int oneChance = oneChances[rg.GetInt32(oneChances.length)];
343-
for (int i = 0; i < count; ++i) {
344-
sb.append((rg.GetInt32(1000) >= oneChance) ? '0' : '1');
345-
}
346-
return EInteger.FromRadixString(sb.toString(), 2);
347-
}
348-
349-
private static EInteger DigitHeavyEInteger(IRandomGenExtended rg, int
350-
count) {
351-
StringBuilder sb = new StringBuilder();
352-
int[] oneChances = {
353-
999, 1, 980, 20, 750, 250, 980,
354-
20, 980, 20, 980, 20, 750, 250,
355-
};
356-
int oneChance = oneChances[rg.GetInt32(oneChances.length)];
357-
for (int i = 0; i < count; ++i) {
358-
sb.append((rg.GetInt32(1000) >= oneChance) ? '0' : '9');
359-
}
360-
return EInteger.FromRadixString(sb.toString(), 10);
361-
}
362-
363-
public static EInteger RandomEInteger(IRandomGenExtended r) {
364-
if (r == null) {
365-
throw new NullPointerException("r");
366-
}
367-
int selection = r.GetInt32(100);
368-
if (selection < 10) {
369-
int count = r.GetInt32(MaxNumberLength);
370-
count = (int)((long)count * r.GetInt32(MaxNumberLength) /
371-
MaxNumberLength);
372-
count = (int)((long)count * r.GetInt32(MaxNumberLength) /
373-
MaxNumberLength);
374-
count = Math.max(count, 1);
375-
if (selection == 0 || selection == 1) {
376-
return BitHeavyEInteger(r, count);
377-
} else if ((selection == 2 || selection == 3) && count < 500) {
378-
return DigitHeavyEInteger(r, count);
379-
}
380-
byte[] bytes = RandomByteString(r, count);
381-
return EInteger.FromBytes(bytes, true);
382-
} else {
383-
byte[] bytes = RandomByteString(
384-
r,
385-
r.GetInt32(MaxShortNumberLength) + 1);
386-
return EInteger.FromBytes(bytes, true);
387-
}
388-
}
389-
390-
public static EInteger RandomEIntegerSmall(IRandomGenExtended r) {
391-
if (r == null) {
392-
throw new NullPointerException("r");
393-
}
394-
byte[] bytes = RandomByteString(
395-
r,
396-
r.GetInt32(MaxShortNumberLength) + 1);
397-
return EInteger.FromBytes(bytes, true);
398-
}
399-
400-
private static int IntInRange(IRandomGenExtended rg, int minInc, int
401-
maxExc) {
402-
return minInc + rg.GetInt32(maxExc - minInc);
403-
}
404-
405-
public static EFloat CloseToPowerOfTwo(IRandomGenExtended rg) {
406-
if (rg == null) {
407-
throw new NullPointerException("rg");
408-
}
409-
int pwr = (rg.GetInt32(100) < 80) ? IntInRange(rg, -20, 20) :
410-
IntInRange(rg, -300, 300);
411-
int pwr2 = pwr - (rg.GetInt32(100) < 80 ? IntInRange(rg, 51, 61) :
412-
IntInRange(rg, 2, 300));
413-
EFloat ef = rg.GetInt32(2) == 0 ? EFloat.Create(1,
414-
pwr).Add(EFloat.Create(1, pwr2)) : EFloat.Create(1,
415-
pwr).Subtract(EFloat.Create(1, pwr2));
416-
if (rg.GetInt32(10) == 0) {
417-
pwr2 = pwr - (rg.GetInt32(100) < 80 ? IntInRange(rg, 51, 61) :
418-
IntInRange(rg, 2, 300));
419-
ef = (rg.GetInt32(2) == 0) ? ef.Add(EFloat.Create(1, pwr2)) :
420-
ef.Subtract(EFloat.Create(1, pwr2));
421-
}
422-
return ef;
423-
}
424-
425-
public static EFloat RandomEFloat(IRandomGenExtended r) {
426-
if (r == null) {
427-
throw new NullPointerException("r");
428-
}
429-
if (r.GetInt32(100) == 0) {
430-
int x = r.GetInt32(3);
431-
if (x == 0) {
432-
return EFloat.PositiveInfinity;
433-
}
434-
if (x == 1) {
435-
return EFloat.NegativeInfinity;
436-
}
437-
if (x == 2) {
438-
return EFloat.NaN;
439-
}
440-
}
441-
return r.GetInt32(100) == 3 ?
442-
CloseToPowerOfTwo(r) : EFloat.Create(
443-
RandomEInteger(r),
444-
EInteger.FromInt64(r.GetInt32(400) - 200));
445-
}
446-
447256
public static String RandomBigIntString(IRandomGenExtended r) {
448257
if (r == null) {
449258
throw new NullPointerException("r");
@@ -459,7 +268,7 @@ public static String RandomBigIntString(IRandomGenExtended r) {
459268
return sb.toString();
460269
}
461270

462-
public static EInteger RandomSmallIntegral(IRandomGenExtended r) {
271+
public static String RandomSmallIntegralString(IRandomGenExtended r) {
463272
if (r == null) {
464273
throw new NullPointerException("r");
465274
}

0 commit comments

Comments
 (0)