Initial BitTree implementation added.

This commit is contained in:
mlemanczyk committed 2026-01-09 16:13:16 +01:00
1 parent 45e3455ff3
commit d88ad25476
11 files changed
+3817 -367

No files matched your search

@@ -0,0 +1,43 @@
using System.Numerics;
using FluentAssertions;
using PerfectNumbers.Core.Cpu;
using Xunit;
namespace PerfectNumbers.Core.Tests;
public class BitTreeSolverTests
{
[Fact]
public void BitTree_FindsKnownDivisor()
{
// 2^11-1 = 2047 = 23 * 89, so k=1 yields divisor 23.
var tester = new MersenneNumberDivisorByDivisorCpuTesterWithForBitTreeDivisorSetForCpuOrder
{
DivisorLimit = new BigInteger(1000),
MinK = BigInteger.One,
};
bool isPrime = tester.IsPrime(11, out bool exhausted, out BigInteger divisor);
isPrime.Should().BeFalse();
exhausted.Should().BeTrue();
divisor.Should().Be(23);
}
[Fact]
public void BitTree_ReportsPrimeWhenNoDivisorFound()
{
// 2^5-1 = 31 is prime.
var tester = new MersenneNumberDivisorByDivisorCpuTesterWithForBitTreeDivisorSetForCpuOrder
{
DivisorLimit = new BigInteger(10_000),
MinK = BigInteger.One,
};
bool isPrime = tester.IsPrime(5, out bool exhausted, out BigInteger divisor);
isPrime.Should().BeTrue();
exhausted.Should().BeTrue();
divisor.Should().Be(BigInteger.Zero);
}
}