Skip to content

Commit

Permalink
Fix Numeric Test when Number Grouping is Empty (#47983)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarekgh authored Feb 8, 2021
1 parent 7487d21 commit 9450aa1
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit 9450aa1

Please sign in to comment.