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 BigInteger outerloop test #111841

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -521,22 +521,23 @@ public static void ToString_InvalidFormat_ThrowsFormatException()
Assert.Throws<FormatException>(() => b.ToString("G000001000000000"));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))] // Requires a lot of memory
[OuterLoop("Takes a long time, allocates a lot of memory")]
[SkipOnMono("Frequently throws OOM on Mono")]
[Fact]
public static void ToString_ValidLargeFormat()
{
BigInteger b = new BigInteger(123456789000m);

// Format precision limit is 999_999_999 (9 digits). Anything larger should throw.
// We use TryFormat rather than ToString to avoid excessive memory usage.

// Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format
b.ToString("E999999999"); // Should not throw
b.ToString("E00000999999999"); // Should not throw
// Check ParseFormatSpecifier in FormatProvider.Number.cs with `E` format.
// Currently disabled since these would still allocate a 2GB buffer before
// returning, leading to OOM in CI.
//Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "E999999999")); // Should not throw
//Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "E00000999999999")); // Should not throw

// Check ParseFormatSpecifier in Number.BigInteger.cs with `G` format
b.ToString("G999999999"); // Should not throw
b.ToString("G00000999999999"); // Should not throw
Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "G999999999")); // Should not throw
Assert.False(b.TryFormat(Span<char>.Empty, out _, format: "G00000999999999")); // Should not throw
}

private static void RunSimpleProviderToStringTests(Random random, string format, NumberFormatInfo provider, int precision, StringFormatter formatter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public static void RunGetBitLengthTests()
public static void RunGetBitLengthTestsLarge()
{
// Very large cases
VerifyGetBitLength(BigInteger.One << 32 << int.MaxValue, int.MaxValue + 32L + 1, 1);
VerifyGetBitLength(BigInteger.One << 64 << int.MaxValue, int.MaxValue + 64L + 1, 1);
// Values which are large but beneath the upper bound of
// (2^31) - 1 bits and which should not cause OOM in CI.
VerifyGetBitLength(BigInteger.One << 32 << (1 << 24), (1 << 24) + 32L + 1, 1);
VerifyGetBitLength(BigInteger.One << 64 << (1 << 24), (1 << 24) + 64L + 1, 1);
}

private static void VerifyLoopGetBitLength(Random random, bool isSmall)
Expand Down
Loading