Initial commit.

This commit is contained in:
Marek Lemańczyk committed 2025-09-09 21:15:57 +02:00
1 parent e5b0fea18c
commit 9f35f6c558
94 files changed
+12857

No files matched your search

@@ -0,0 +1,25 @@
using FluentAssertions;
using Xunit;
namespace PerfectNumbers.Core.Tests;
[Trait("Category", "Fast")]
public class PrimeTesterGcdTests
{
[Theory]
[InlineData(81UL, true)]
[InlineData(101UL, false)]
public void SharesFactorWithMaxExponent_detects_gcd(ulong n, bool expected)
{
PrimeTester.SharesFactorWithMaxExponent(n).Should().Be(expected);
}
[Fact]
public void SharesFactorWithMaxExponentBatch_filters_values()
{
ulong[] values = [81UL, 101UL];
Span<byte> results = stackalloc byte[values.Length];
PrimeTester.SharesFactorWithMaxExponentBatch(values, results);
results.ToArray().Should().Equal(new byte[] { 1, 0 });
}
}
@@ -0,0 +1,39 @@
using FluentAssertions;
using PerfectNumbers.Core.Gpu;
using Xunit;
namespace PerfectNumbers.Core.Tests;
public class PrimeTesterIsPrimeTests
{
[Theory]
[Trait("Category", "Fast")]
[InlineData(1UL, false)]
[InlineData(2UL, true)]
[InlineData(3UL, true)]
[InlineData(4UL, false)]
[InlineData(7UL, true)]
[InlineData(97UL, true)]
[InlineData(121UL, false)]
public void IsPrime_returns_expected_results(ulong n, bool expected)
{
var tester = new PrimeTester();
tester.IsPrime(n, CancellationToken.None).Should().Be(expected);
}
[Fact]
[Trait("Category", "Fast")]
public void IsPrimeGpu_falls_back_to_cpu_when_forced()
{
var tester = new PrimeTester();
GpuContextPool.ForceCpu = true;
tester.IsPrimeGpu(11UL, CancellationToken.None).Should().BeTrue();
tester.IsPrimeGpu(12UL, CancellationToken.None).Should().BeFalse();
GpuContextPool.ForceCpu = false;
}
}