Skip to content

Commit 22677d7

Browse files
committed
move certain methods from RandomObjects to RandomNumerics
1 parent a816ac1 commit 22677d7

7 files changed

+308
-280
lines changed

Test/DecimalTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void TestDecimalString() {
5555
// ", " + (sw3.ElapsedMilliseconds));
5656
}
5757
// sw3.Start();
58-
EDecimal ed = RandomObjects.RandomEDecimal(fr);
58+
EDecimal ed = RandomNumerics.RandomEDecimal(fr);
5959
// sw3.Stop();
6060
// Reduce to Decimal128. Without this reduction,
6161
// Decimal.Parse would run significantly more slowly

Test/EDecimalTest.cs

+25-25
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ private static void TestAddCloseExponent(RandomGenerator fr, int exp) {
115115
EInteger exp1 = EInteger.FromInt32(exp)
116116
.Add(EInteger.FromInt32(fr.UniformInt(32) - 16));
117117
EInteger exp2 = exp1.Add(EInteger.FromInt32(fr.UniformInt(18) - 9));
118-
EInteger mant1 = RandomObjects.RandomEInteger(fr);
119-
EInteger mant2 = RandomObjects.RandomEInteger(fr);
118+
EInteger mant1 = RandomNumerics.RandomEInteger(fr);
119+
EInteger mant2 = RandomNumerics.RandomEInteger(fr);
120120
EDecimal decA = EDecimal.Create(mant1, exp1);
121121
EDecimal decB = EDecimal.Create(mant2, exp2);
122122
EDecimal decC = decA.Add(decB);
@@ -179,15 +179,15 @@ public void TestAddThenCompare() {
179179
public void TestCompareTo() {
180180
var r = new RandomGenerator();
181181
for (var i = 0; i < 500; ++i) {
182-
EDecimal bigintA = RandomObjects.RandomEDecimal(r);
183-
EDecimal bigintB = RandomObjects.RandomEDecimal(r);
184-
EDecimal bigintC = RandomObjects.RandomEDecimal(r);
182+
EDecimal bigintA = RandomNumerics.RandomEDecimal(r);
183+
EDecimal bigintB = RandomNumerics.RandomEDecimal(r);
184+
EDecimal bigintC = RandomNumerics.RandomEDecimal(r);
185185
TestCommon.CompareTestRelations(bigintA, bigintB, bigintC);
186186
}
187187
// Test equivalence of EInteger and EDecimal for integers
188188
for (var i = 0; i < 3000; ++i) {
189-
EInteger bigintA = RandomObjects.RandomEInteger(r);
190-
EInteger bigintB = RandomObjects.RandomEInteger(r);
189+
EInteger bigintA = RandomNumerics.RandomEInteger(r);
190+
EInteger bigintB = RandomNumerics.RandomEInteger(r);
191191
EInteger bigintC = bigintA.Add(bigintB);
192192
EDecimal ba1 = EDecimal.FromEInteger(bigintA)
193193
.Add(EDecimal.FromEInteger(bigintB));
@@ -267,7 +267,7 @@ public void TestCompareToBinary() {
267267
}
268268
var r = new RandomGenerator();
269269
for (var i = 0; i < 30000; ++i) {
270-
EInteger bigintA = RandomObjects.RandomEInteger(r);
270+
EInteger bigintA = RandomNumerics.RandomEInteger(r);
271271
int cmp = EDecimal.FromEInteger(bigintA).CompareToBinary(
272272
EFloat.FromEInteger(bigintA));
273273
Assert.AreEqual(0, cmp);
@@ -492,7 +492,7 @@ public void TestConversions() {
492492
TestConversionsOne(EDecimal.FromString("4766857907817990.0000000000"));
493493
var fr = new RandomGenerator();
494494
for (var i = 0; i < 5000; ++i) {
495-
EDecimal enumber = RandomObjects.RandomEDecimal(fr);
495+
EDecimal enumber = RandomNumerics.RandomEDecimal(fr);
496496
TestConversionsOne(enumber);
497497
}
498498
TestConversionsOne(EDecimal.FromString("-0.8995"));
@@ -1291,8 +1291,8 @@ public void TestDivide() {
12911291
EDecimalTest.TestDivideOne(ed1, ed2);
12921292
var fr = new RandomGenerator();
12931293
for (var i = 0; i < 5000; ++i) {
1294-
ed1 = RandomObjects.RandomEDecimal(fr);
1295-
ed2 = RandomObjects.RandomEDecimal(fr);
1294+
ed1 = RandomNumerics.RandomEDecimal(fr);
1295+
ed2 = RandomNumerics.RandomEDecimal(fr);
12961296
TestDivideOne(ed1, ed2);
12971297
}
12981298
try {
@@ -1376,8 +1376,8 @@ public void TestEquals() {
13761376
}
13771377
var r = new RandomGenerator();
13781378
for (var i = 0; i < 500; ++i) {
1379-
EDecimal bigintA = RandomObjects.RandomEDecimal(r);
1380-
EDecimal bigintB = RandomObjects.RandomEDecimal(r);
1379+
EDecimal bigintA = RandomNumerics.RandomEDecimal(r);
1380+
EDecimal bigintB = RandomNumerics.RandomEDecimal(r);
13811381
TestCommon.AssertEqualsHashCode(bigintA, bigintB);
13821382
}
13831383
}
@@ -1686,7 +1686,7 @@ public void TestEDecimalSingle() {
16861686
public void TestFromEInteger() {
16871687
var fr = new RandomGenerator();
16881688
for (var i = 0; i < 5000; ++i) {
1689-
EInteger ei = RandomObjects.RandomEInteger(fr);
1689+
EInteger ei = RandomNumerics.RandomEInteger(fr);
16901690
EDecimal edec = EDecimal.FromEInteger(ei);
16911691
Assert.AreEqual(EInteger.Zero, edec.Exponent);
16921692
Assert.AreEqual(ei, edec.Mantissa);
@@ -2759,8 +2759,8 @@ public void TestMax() {
27592759
}
27602760
var r = new RandomGenerator();
27612761
for (var i = 0; i < 500; ++i) {
2762-
EDecimal bigintA = RandomObjects.RandomEDecimal(r);
2763-
EDecimal bigintB = RandomObjects.RandomEDecimal(r);
2762+
EDecimal bigintA = RandomNumerics.RandomEDecimal(r);
2763+
EDecimal bigintB = RandomNumerics.RandomEDecimal(r);
27642764
if (!bigintA.IsFinite || !bigintB.IsFinite) {
27652765
continue;
27662766
}
@@ -2826,8 +2826,8 @@ public void TestMin() {
28262826
}
28272827
var r = new RandomGenerator();
28282828
for (var i = 0; i < 500; ++i) {
2829-
EDecimal bigintA = RandomObjects.RandomEDecimal(r);
2830-
EDecimal bigintB = RandomObjects.RandomEDecimal(r);
2829+
EDecimal bigintA = RandomNumerics.RandomEDecimal(r);
2830+
EDecimal bigintB = RandomNumerics.RandomEDecimal(r);
28312831
if (!bigintA.IsFinite || !bigintB.IsFinite) {
28322832
continue;
28332833
}
@@ -3039,7 +3039,7 @@ public void TestMultiplyAndSubtract() {
30393039
public void TestCopySign() {
30403040
var r = new RandomGenerator();
30413041
for (var i = 0; i < 1000; ++i) {
3042-
EDecimal ed = RandomObjects.RandomEDecimal(r);
3042+
EDecimal ed = RandomNumerics.RandomEDecimal(r);
30433043
ed = ed.CopySign(EDecimal.Zero);
30443044
Assert.IsFalse(ed.IsNegative);
30453045
ed = ed.CopySign(EDecimal.NegativeZero);
@@ -3080,7 +3080,7 @@ public void TestAddSpecific2() {
30803080
public void TestNegate() {
30813081
var r = new RandomGenerator();
30823082
for (var i = 0; i < 1000; ++i) {
3083-
EDecimal ed = RandomObjects.RandomEDecimal(r);
3083+
EDecimal ed = RandomNumerics.RandomEDecimal(r);
30843084
ed = ed.CopySign(EDecimal.Zero);
30853085
Assert.IsTrue(ed.Negate().IsNegative);
30863086
ed = ed.CopySign(EDecimal.NegativeZero);
@@ -3612,7 +3612,7 @@ public void TestToSizedEInteger() {
36123612
}
36133613
var rg = new RandomGenerator();
36143614
for (var i = 0; i < 75000; ++i) {
3615-
EDecimal ed = RandomObjects.RandomEDecimal(rg);
3615+
EDecimal ed = RandomNumerics.RandomEDecimal(rg);
36163616
bool bv = rg.UniformInt(2) == 0;
36173617
int msb = rg.UniformInt(129);
36183618
try {
@@ -3624,7 +3624,7 @@ public void TestToSizedEInteger() {
36243624
}
36253625
}
36263626
for (var i = 0; i < 10000; ++i) {
3627-
EInteger ei = RandomObjects.RandomEInteger(rg);
3627+
EInteger ei = RandomNumerics.RandomEInteger(rg);
36283628
int expo = rg.UniformInt(20);
36293629
bool bv = rg.UniformInt(2) == 0;
36303630
int msb = rg.UniformInt(129);
@@ -3765,7 +3765,7 @@ public void TestToEIntegerIfExact() {
37653765
}
37663766
var rg = new RandomGenerator();
37673767
for (var i = 0; i < 1000; ++i) {
3768-
EInteger ei = RandomObjects.RandomEInteger(rg);
3768+
EInteger ei = RandomNumerics.RandomEInteger(rg);
37693769
int expo = rg.UniformInt(20);
37703770
EDecimal ed = EDecimal.FromEInteger(ei)
37713771
.ScaleByPowerOfTen(expo).MovePointLeft(expo);
@@ -3941,7 +3941,7 @@ public void TestToDouble() {
39413941
Assert.IsTrue(dbl == 0.0);
39423942
for (var i = 0; i < 100000; ++i) {
39433943
EDecimal edec;
3944-
edec = RandomObjects.RandomEDecimal(fr);
3944+
edec = RandomNumerics.RandomEDecimal(fr);
39453945
if (edec.IsFinite) {
39463946
dbl = edec.ToDouble();
39473947
if (Double.IsNegativeInfinity(dbl)) {
@@ -5451,7 +5451,7 @@ public void TestToSingle() {
54515451
Assert.IsTrue(sng == 0.0);
54525452
for (var i = 0; i < 100000; ++i) {
54535453
EDecimal edec;
5454-
edec = RandomObjects.RandomEDecimal(fr);
5454+
edec = RandomNumerics.RandomEDecimal(fr);
54555455
if (edec.IsFinite) {
54565456
sng = edec.ToSingle();
54575457
if (Single.IsNegativeInfinity(sng)) {

Test/EFloatTest.cs

+19-19
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static bool TestCompareToBinary2(EFloat ef) {
9797
public void TestCompareToBinary2Test() {
9898
var rg = new RandomGenerator();
9999
for (int i = 0; i < 1000; ++i) {
100-
TestCompareToBinary2(RandomObjects.RandomEFloat(rg));
100+
TestCompareToBinary2(RandomNumerics.RandomEFloat(rg));
101101
}
102102
}
103103
[Test]
@@ -165,9 +165,9 @@ public void TestDivSpecial() {
165165
public void TestCompareTo() {
166166
var r = new RandomGenerator();
167167
for (var i = 0; i < 500; ++i) {
168-
EFloat bigintA = RandomObjects.RandomEFloat(r);
169-
EFloat bigintB = RandomObjects.RandomEFloat(r);
170-
EFloat bigintC = RandomObjects.RandomEFloat(r);
168+
EFloat bigintA = RandomNumerics.RandomEFloat(r);
169+
EFloat bigintB = RandomNumerics.RandomEFloat(r);
170+
EFloat bigintC = RandomNumerics.RandomEFloat(r);
171171
TestCommon.CompareTestRelations(bigintA, bigintB, bigintC);
172172
}
173173
TestCommon.CompareTestLess(EFloat.Zero, EFloat.NaN);
@@ -271,8 +271,8 @@ public void TestDivide() {
271271
}
272272
var fr = new RandomGenerator();
273273
for (var i = 0; i < 5000; ++i) {
274-
EFloat ed1 = RandomObjects.RandomEFloat(fr);
275-
EFloat ed2 = RandomObjects.RandomEFloat(fr);
274+
EFloat ed1 = RandomNumerics.RandomEFloat(fr);
275+
EFloat ed2 = RandomNumerics.RandomEFloat(fr);
276276
if (!ed1.IsFinite || !ed2.IsFinite) {
277277
continue;
278278
}
@@ -335,8 +335,8 @@ public void TestEquals() {
335335
}
336336
var r = new RandomGenerator();
337337
for (var i = 0; i < 500; ++i) {
338-
EFloat bigintA = RandomObjects.RandomEFloat(r);
339-
EFloat bigintB = RandomObjects.RandomEFloat(r);
338+
EFloat bigintA = RandomNumerics.RandomEFloat(r);
339+
EFloat bigintB = RandomNumerics.RandomEFloat(r);
340340
TestCommon.AssertEqualsHashCode(bigintA, bigintB);
341341
}
342342
}
@@ -616,7 +616,7 @@ public void TestFloatDecimalSpecific() {
616616
public void TestFloatDecimalRoundTrip() {
617617
var r = new RandomGenerator();
618618
for (var i = 0; i < 5000; ++i) {
619-
EFloat ef = RandomObjects.RandomEFloat(r);
619+
EFloat ef = RandomNumerics.RandomEFloat(r);
620620
EDecimal ed = ef.ToEDecimal();
621621
EFloat ef2 = ed.ToEFloat();
622622
// Tests that values converted from float to decimal and
@@ -1354,8 +1354,8 @@ public void TestMax() {
13541354
}
13551355
var r = new RandomGenerator();
13561356
for (var i = 0; i < 500; ++i) {
1357-
EFloat bigintA = RandomObjects.RandomEFloat(r);
1358-
EFloat bigintB = RandomObjects.RandomEFloat(r);
1357+
EFloat bigintA = RandomNumerics.RandomEFloat(r);
1358+
EFloat bigintB = RandomNumerics.RandomEFloat(r);
13591359
if (!bigintA.IsFinite || !bigintB.IsFinite) {
13601360
continue;
13611361
}
@@ -1422,8 +1422,8 @@ public void TestMin() {
14221422

14231423
var r = new RandomGenerator();
14241424
for (var i = 0; i < 500; ++i) {
1425-
EFloat bigintA = RandomObjects.RandomEFloat(r);
1426-
EFloat bigintB = RandomObjects.RandomEFloat(r);
1425+
EFloat bigintA = RandomNumerics.RandomEFloat(r);
1426+
EFloat bigintB = RandomNumerics.RandomEFloat(r);
14271427
if (!bigintA.IsFinite || !bigintB.IsFinite) {
14281428
continue;
14291429
}
@@ -1565,7 +1565,7 @@ public void TestIntegerDoubleSingle() {
15651565
EInteger.FromString("36410213260593956497280175692088585748480"));
15661566
var rg = new RandomGenerator();
15671567
for (var i = 0; i < 1000; ++i) {
1568-
EInteger ei = RandomObjects.RandomEInteger(rg);
1568+
EInteger ei = RandomNumerics.RandomEInteger(rg);
15691569
TestIntegerDoubleSingleOne(ei);
15701570
}
15711571
}
@@ -1780,7 +1780,7 @@ public void TestPow() {
17801780
}
17811781
var rg = new RandomGenerator();
17821782
for (var i = 0; i < 500; ++i) {
1783-
EInteger ei = RandomObjects.RandomEInteger(rg);
1783+
EInteger ei = RandomNumerics.RandomEInteger(rg);
17841784
EInteger thresh = EInteger.FromInt64(6999999999999999999L);
17851785
if (ei.Abs().CompareTo(thresh) < 0) {
17861786
ei = ei.Add(ei.Sign < 0 ? thresh.Negate() : thresh);
@@ -2824,7 +2824,7 @@ public void TestDoubleShortestString() {
28242824
public void TestConversions() {
28252825
var fr = new RandomGenerator();
28262826
for (var i = 0; i < 20000; ++i) {
2827-
EFloat enumber = RandomObjects.RandomEFloat(fr);
2827+
EFloat enumber = RandomNumerics.RandomEFloat(fr);
28282828
TestConversionsOne(enumber);
28292829
}
28302830
}
@@ -3307,7 +3307,7 @@ public void TestToEIntegerIfExact() {
33073307
}
33083308
for (var i = 0; i < 1000; ++i) {
33093309
var rg = new RandomGenerator();
3310-
EInteger ei = RandomObjects.RandomEInteger(rg);
3310+
EInteger ei = RandomNumerics.RandomEInteger(rg);
33113311
int expo = rg.UniformInt(20);
33123312
EFloat ed = EFloat.FromEInteger(ei).ScaleByPowerOfTwo(
33133313
expo).MovePointLeft(expo);
@@ -3411,7 +3411,7 @@ public void TestToSizedEInteger() {
34113411
for (var i = 0; i < 100000; ++i) {
34123412
bool b = rg.UniformInt(2) == 0;
34133413
TestSizedEIntegerOne(
3414-
RandomObjects.RandomEFloat(rg),
3414+
RandomNumerics.RandomEFloat(rg),
34153415
b,
34163416
rg.UniformInt(129));
34173417
}
@@ -3547,7 +3547,7 @@ public void TestToSingle() {
35473547
public void TestToString() {
35483548
var fr = new RandomGenerator();
35493549
for (var i = 0; i < 1000; ++i) {
3550-
EFloat dec = RandomObjects.RandomEFloat(fr);
3550+
EFloat dec = RandomNumerics.RandomEFloat(fr);
35513551
if (dec.IsFinite) {
35523552
EDecimal ed = EDecimal.FromString(dec.ToString());
35533553
Assert.AreEqual(0, ed.CompareToBinary(dec));

0 commit comments

Comments
 (0)