Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Numeric Test when Number Grouping is Empty #47983

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ private static void RunFormatProviderParseStrings()
VerifyFormatParse("123&4567^ <", NumberStyles.Any, nfi, new BigInteger(-1234567));
}

private static bool NoGrouping(int[] sizes) => sizes.Length == 0 || (sizes.Length == 1 && sizes[0] == 0);

private static void VerifyDefaultParse(Random random)
{
// BasicTests
Expand Down Expand Up @@ -219,7 +221,14 @@ private static void VerifyDefaultParse(Random random)
sizes = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes;
seperator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
digits = GenerateGroups(sizes, seperator, random);
VerifyFailParseToString(digits, typeof(FormatException));
if (NoGrouping(sizes))
{
VerifyParseToString(digits);
}
else
{
VerifyFailParseToString(digits, typeof(FormatException));
}
}

// Exponent
Expand Down Expand Up @@ -341,7 +350,7 @@ private static void VerifyNumberStyles(NumberStyles ns, Random random)
sizes = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes;
seperator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator;
digits = GenerateGroups(sizes, seperator, random);
VerifyParseToString(digits, ns, ((ns & NumberStyles.AllowThousands) != 0));
VerifyParseToString(digits, ns, NoGrouping(sizes) || ((ns & NumberStyles.AllowThousands) != 0));
}

// Exponent
Expand Down Expand Up @@ -727,6 +736,11 @@ private static string GenerateGroups(int[] sizes, string seperator, Random rando
int num_digits = random.Next(10, 100);
string digits = string.Empty;

if (NoGrouping(sizes))
{
return GetDigitSequence(1, 100, random);
}

total = 0;
total_sizes.Add(0);
for (int j = 0; ((j < (sizes.Length - 1)) && (total < 101)); j++)
Expand Down