Add CalculationResultsFile coverage
This commit is contained in:
1 parent
2c6e9f5460
commit
1e738f9e0d
5 files changed
+448
-328
No files matched your search
@@ -1,8 +1,13 @@
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using FluentAssertions;
|
||||
using PerfectNumbers.Core;
|
||||
using PerfectNumbers.Core.Gpu;
|
||||
using Xunit;
|
||||
|
||||
using EvenPerfectBitScanner.IO;
|
||||
|
||||
namespace EvenPerfectBitScanner.Tests;
|
||||
|
||||
[Trait("Category", "Fast")]
|
||||
@@ -11,41 +16,26 @@ public class ResultsFileNameTests
|
||||
[Fact]
|
||||
public void BuildResultsFileName_contains_reduction_and_devices()
|
||||
{
|
||||
var programType = typeof(global::EvenPerfectBitScanner.Program);
|
||||
var method = programType.GetMethod(
|
||||
"BuildResultsFileName",
|
||||
BindingFlags.NonPublic | BindingFlags.Static,
|
||||
binder: null,
|
||||
types: new[]
|
||||
{
|
||||
typeof(bool), typeof(int), typeof(int), typeof(global::PerfectNumbers.Core.GpuKernelType),
|
||||
typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(bool), typeof(NttBackend), typeof(int), typeof(int), typeof(int), typeof(ulong), typeof(ModReductionMode), typeof(string), typeof(string), typeof(string)
|
||||
},
|
||||
modifiers: null)!;
|
||||
|
||||
string name = (string)method.Invoke(null, new object[]
|
||||
{
|
||||
true, // bitInc
|
||||
8, // threads
|
||||
1, // block
|
||||
global::PerfectNumbers.Core.GpuKernelType.Incremental,
|
||||
false, // useLucasFlag
|
||||
false, // useDivisorFlag
|
||||
false, // useByDivisorFlag
|
||||
true, // mersenneOnGpu (unused inside name content, devices passed explicitly below)
|
||||
false, // useOrder
|
||||
false, // useModWorkaround
|
||||
false, // useGcd
|
||||
NttBackend.Staged,
|
||||
1, // gpuPrimeThreads
|
||||
32, // llSlice
|
||||
1024, // gpuScanBatch
|
||||
1000UL, // warmupLimit
|
||||
ModReductionMode.Barrett128,
|
||||
"gpu", // mersenneDevice
|
||||
"gpu", // primesDevice
|
||||
"gpu" // orderDevice
|
||||
})!;
|
||||
string name = CalculationResultsFile.BuildFileName(
|
||||
bitInc: true,
|
||||
threads: 8,
|
||||
block: 1,
|
||||
kernelType: GpuKernelType.Incremental,
|
||||
useLucasFlag: false,
|
||||
useDivisorFlag: false,
|
||||
useByDivisorFlag: false,
|
||||
mersenneOnGpu: true,
|
||||
useOrder: false,
|
||||
useGcd: false,
|
||||
nttBackend: NttBackend.Staged,
|
||||
gpuPrimeThreads: 1,
|
||||
llSlice: 32,
|
||||
gpuScanBatch: 1024,
|
||||
warmupLimit: 1000UL,
|
||||
reduction: ModReductionMode.Barrett128,
|
||||
mersenneDevice: "gpu",
|
||||
primesDevice: "gpu",
|
||||
orderDevice: "gpu");
|
||||
|
||||
name.Should().Contain("ntt-staged");
|
||||
name.Should().Contain("red-barrett128");
|
||||
@@ -53,4 +43,63 @@ public class ResultsFileNameTests
|
||||
name.Should().Contain("primesdev-gpu");
|
||||
name.Should().Contain("orderdev-gpu");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadCandidatesWithinRange_skips_comments_and_applies_limit()
|
||||
{
|
||||
string path = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
File.WriteAllLines(path, new[]
|
||||
{
|
||||
"# header",
|
||||
"5 7",
|
||||
string.Empty,
|
||||
"11",
|
||||
"17",
|
||||
"19"
|
||||
});
|
||||
|
||||
List<ulong> candidates = CalculationResultsFile.LoadCandidatesWithinRange(path, (UInt128)13, maxPrimeConfigured: true, out int skipped);
|
||||
|
||||
candidates.Should().Equal(5UL, 7UL, 11UL);
|
||||
skipped.Should().Be(2);
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnumerateCandidates_reads_valid_rows_and_skips_invalid_entries()
|
||||
{
|
||||
string path = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
File.WriteAllLines(path, new[]
|
||||
{
|
||||
"p,searched,detailed,passed",
|
||||
"5,true,true,true",
|
||||
string.Empty,
|
||||
"11,false,false,true",
|
||||
"invalid",
|
||||
"13,true,true,false"
|
||||
});
|
||||
|
||||
List<(ulong P, bool Detailed, bool Passed)> rows = new();
|
||||
CalculationResultsFile.EnumerateCandidates(path, (p, detailed, passed) => rows.Add((p, detailed, passed)));
|
||||
|
||||
rows.Should().Equal(new (ulong, bool, bool)[]
|
||||
{
|
||||
(5UL, true, true),
|
||||
(11UL, false, true),
|
||||
(13UL, true, false)
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user