Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit d361504

Browse files
committed
Fix System.Globalization tests to use non-static RNG
1 parent fc96be9 commit d361504

22 files changed

+178
-602
lines changed

src/System.Globalization.Calendars/tests/Generator.cs renamed to src/Common/tests/System/RandomDataGenerator.cs

Lines changed: 121 additions & 144 deletions
Large diffs are not rendered by default.

src/System.Globalization/tests/CompareInfo/CompareInfoCompare2.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace System.Globalization.Tests
1010
{
1111
public class CompareInfoCompare2
1212
{
13+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1314
public static string[] InterestingStrings = new string[] { null, "", "a", "1", "-", "A", "!", "abc", "aBc", "a\u0400Bc", "I", "i", "\u0130", "\u0131", "A", "\uFF21", "\uFE57" };
1415

1516
// PosTest1: Compare interesting strings ordinally
@@ -31,7 +32,7 @@ public void CompareManyCharacters()
3132
{
3233
for (int i = 0; i < 40; i++)
3334
{
34-
char c = TestLibrary.Generator.GetChar(-55);
35+
char c = _generator.GetChar(-55);
3536
Assert.Equal(0, CultureInfo.CurrentCulture.CompareInfo.Compare(new string(new char[] { c }), new string(new char[] { c }), CompareOptions.Ordinal));
3637
for (int j = 0; j < (int)c; j++)
3738
{
@@ -48,8 +49,8 @@ public void CompareManyStrings()
4849
{
4950
for (int i = 0; i < 1000; i++)
5051
{
51-
string str1 = TestLibrary.Generator.GetString(-55, false, 5, 20);
52-
string str2 = TestLibrary.Generator.GetString(-55, false, 5, 20);
52+
string str1 = _generator.GetString(-55, false, 5, 20);
53+
string str2 = _generator.GetString(-55, false, 5, 20);
5354
Assert.Equal(0, CultureInfo.CurrentCulture.CompareInfo.Compare(str1, str1, CompareOptions.Ordinal));
5455
Assert.Equal(0, CultureInfo.CurrentCulture.CompareInfo.Compare(str2, str2, CompareOptions.Ordinal));
5556
TestStrings(str1, str2);

src/System.Globalization/tests/CompareInfo/CompareInfoIndexOf2.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace System.Globalization.Tests
1010
{
1111
public class CompareInfoIndexOf2
1212
{
13+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
1314
public static string[] InterestingStrings = new string[] { "", "a", "1", "-", "A", "!", "abc", "aBc", "a\u0400Bc", "I", "i", "\u0130", "\u0131", "A", "\uFF21", "\uFE57" };
1415

1516
// PosTest1: Compare interesting strings ordinally
@@ -31,8 +32,8 @@ public void CompareManyStrings()
3132
{
3233
for (int i = 0; i < 1000; i++)
3334
{
34-
string str1 = TestLibrary.Generator.GetString(-55, false, 5, 20);
35-
string str2 = TestLibrary.Generator.GetString(-55, false, 5, 20);
35+
string str1 = _generator.GetString(-55, false, 5, 20);
36+
string str2 = _generator.GetString(-55, false, 5, 20);
3637
Assert.Equal(0, CultureInfo.CurrentCulture.CompareInfo.IndexOf(str1, str1, CompareOptions.Ordinal));
3738
Assert.Equal(0, CultureInfo.CurrentCulture.CompareInfo.IndexOf(str2, str2, CompareOptions.Ordinal));
3839
TestStrings(str1, str2);

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoFullDateTimePattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoFullDateTimePattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call FullDateTimePattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
public void TestGetter()
@@ -24,7 +26,7 @@ public void TestSetter()
2426
VerificationHelper(new DateTimeFormatInfo(), "dddd", true);
2527
VerificationHelper(new DateTimeFormatInfo(), "F", true);
2628
VerificationHelper(new DateTimeFormatInfo(), "HH:mm:ss dddd, dd MMMM yyyy", true);
27-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
29+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2830
}
2931

3032
// NegTest1: ArgumentNullException should be thrown when The property is being set to a null reference

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoLongDatePattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoLongDatePattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call LongDatePattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
public void PosTest1()
@@ -24,7 +26,7 @@ public void PosTest2()
2426
VerificationHelper(new DateTimeFormatInfo(), "dddd", true);
2527
VerificationHelper(new DateTimeFormatInfo(), "D", true);
2628
VerificationHelper(new DateTimeFormatInfo(), "HH:mm:ss dddd, dd MMMM yyyy", true);
27-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
29+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2830
VerificationHelper(new DateTimeFormatInfo(), "dddd, dd MMMM yyyy", true);
2931
}
3032

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoLongTimePattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoLongTimePattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call LongTimePattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
public void PosTest1()
@@ -24,7 +26,7 @@ public void PosTest2()
2426
VerificationHelper(new DateTimeFormatInfo(), "HH", true);
2527
VerificationHelper(new DateTimeFormatInfo(), "T", true);
2628
VerificationHelper(new DateTimeFormatInfo(), "HH:mm:ss dddd, dd MMMM yyyy", true);
27-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
29+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2830
VerificationHelper(new DateTimeFormatInfo(), "HH:mm:ss", true);
2931
}
3032

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoMonthDayPattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoMonthDayPattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call MonthDayPattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
public void PosTest1()
@@ -24,7 +26,7 @@ public void PosTest2()
2426
VerificationHelper(new DateTimeFormatInfo(), "MMM dd", true);
2527
VerificationHelper(new DateTimeFormatInfo(), "M", true);
2628
VerificationHelper(new DateTimeFormatInfo(), "dd MMMM", true);
27-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
29+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2830
VerificationHelper(new DateTimeFormatInfo(), "MMMM dd", true);
2931
VerificationHelper(new DateTimeFormatInfo(), "m", true);
3032
}

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoShortDatePattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoShortDatePattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call ShortDatePattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
public void TestGetter()
@@ -23,7 +25,7 @@ public void TestSetter()
2325
VerificationHelper(new DateTimeFormatInfo(), "MM/dd/yyyy", true);
2426
VerificationHelper(new DateTimeFormatInfo(), "MM-DD-yyyy", true);
2527
VerificationHelper(new DateTimeFormatInfo(), "d", true);
26-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
28+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2729
}
2830

2931
// NegTest1: ArgumentNullException should be thrown when The property is being set to a null reference

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoShortTimePattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoShortTimePattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call ShortTimePattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
public void TestGetter()
@@ -22,7 +24,7 @@ public void TestSetter()
2224
{
2325
VerificationHelper(new DateTimeFormatInfo(), "HH:mm", true);
2426
VerificationHelper(new DateTimeFormatInfo(), "t", true);
25-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
27+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2628
}
2729

2830
// NegTest1: ArgumentNullException should be thrown when The property is being set to a null reference

src/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoYearMonthPattern.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace System.Globalization.Tests
99
{
1010
public class DateTimeFormatInfoYearMonthPattern
1111
{
12+
private readonly RandomDataGenerator _generator = new RandomDataGenerator();
13+
1214
// PosTest1: Call YearMonthPattern getter method should return correct value for InvariantInfo
1315
[Fact]
1416
[ActiveIssue(846, PlatformID.AnyUnix)]
@@ -25,7 +27,7 @@ public void TestSetter()
2527
VerificationHelper(new DateTimeFormatInfo(), "yyyy MMMM", true);
2628
VerificationHelper(new DateTimeFormatInfo(), "y", true);
2729
VerificationHelper(new DateTimeFormatInfo(), "Y", true);
28-
VerificationHelper(new DateTimeFormatInfo(), TestLibrary.Generator.GetString(-55, false, 1, 256), true);
30+
VerificationHelper(new DateTimeFormatInfo(), _generator.GetString(-55, false, 1, 256), true);
2931
}
3032

3133
// NegTest1: ArgumentNullException should be thrown when The property is being set to a null reference

0 commit comments

Comments
 (0)