Ensure GPU residue copies are synchronized and cover high divisor sets

This commit is contained in:
Marek Lemańczyk committed 2025-09-20 22:49:37 +02:00
1 parent 633c94906a
commit 7449f146d9
7 files changed
+215 -2

No files matched your search

@@ -0,0 +1,52 @@
using System.Threading;
using FluentAssertions;
using PerfectNumbers.Core;
using PerfectNumbers.Core.Gpu;
using Xunit;
namespace PerfectNumbers.Core.Tests.Gpu;
[Trait("Category", "Fast")]
public class PrimeTesterGpuTests
{
[Fact]
public void IsPrimeGpu_accepts_known_primes()
{
GpuContextPool.ForceCpu = false;
try
{
var tester = new PrimeTester();
ulong[] primes = [5UL, 31UL, 61UL, 89UL, 107UL, 127UL];
foreach (ulong prime in primes)
{
tester.IsPrimeGpu(prime, CancellationToken.None).Should().BeTrue();
}
}
finally
{
GpuContextPool.ForceCpu = false;
GpuContextPool.DisposeAll();
}
}
[Fact]
public void IsPrimeGpu_rejects_composites()
{
GpuContextPool.ForceCpu = false;
try
{
var tester = new PrimeTester();
ulong[] composites = [21UL, 25UL, 27UL, 35UL, 55UL];
foreach (ulong composite in composites)
{
tester.IsPrimeGpu(composite, CancellationToken.None).Should().BeFalse();
}
}
finally
{
GpuContextPool.ForceCpu = false;
GpuContextPool.DisposeAll();
}
}
}