数値の部品の試験プロジェクトを作りFFTの試験を移す
このコミットが含まれているのは:
3ファイル変更
+34
-3
検索条件に一致するファイルはありません
@@ -0,0 +1,91 @@
|
||||
namespace SpectralConvolution.Tests;
|
||||
|
||||
public sealed class FastFourierTransformTests
|
||||
{
|
||||
[Fact]
|
||||
public void ForwardOfImpulseIsConstant()
|
||||
{
|
||||
var real = new double[16];
|
||||
var imaginary = new double[16];
|
||||
real[0] = 1;
|
||||
|
||||
FastFourierTransform.Forward(real, imaginary);
|
||||
|
||||
for (var index = 0; index < real.Length; index++)
|
||||
{
|
||||
Assert.True(Math.Abs(real[index] - 1) < 1e-12);
|
||||
Assert.True(Math.Abs(imaginary[index]) < 1e-12);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OneDimensionalRoundTripRestoresInput()
|
||||
{
|
||||
var random = new Random(12345);
|
||||
var real = new double[256];
|
||||
var imaginary = new double[256];
|
||||
for (var index = 0; index < real.Length; index++)
|
||||
{
|
||||
real[index] = random.NextDouble() * 2 - 1;
|
||||
imaginary[index] = random.NextDouble() * 2 - 1;
|
||||
}
|
||||
var expectedReal = (double[])real.Clone();
|
||||
var expectedImaginary = (double[])imaginary.Clone();
|
||||
|
||||
FastFourierTransform.Forward(real, imaginary);
|
||||
FastFourierTransform.Inverse(real, imaginary);
|
||||
|
||||
AssertMaximumError(expectedReal, expectedImaginary, real, imaginary, 1e-11);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TwoDimensionalRoundTripRestoresInput()
|
||||
{
|
||||
var random = new Random(67890);
|
||||
var length = 64 * 32;
|
||||
var real = new double[length];
|
||||
var imaginary = new double[length];
|
||||
for (var index = 0; index < length; index++)
|
||||
{
|
||||
real[index] = random.NextDouble();
|
||||
imaginary[index] = random.NextDouble();
|
||||
}
|
||||
var expectedReal = (double[])real.Clone();
|
||||
var expectedImaginary = (double[])imaginary.Clone();
|
||||
|
||||
FastFourierTransform.Forward2D(real, imaginary, 64, 32);
|
||||
FastFourierTransform.Inverse2D(real, imaginary, 64, 32);
|
||||
|
||||
AssertMaximumError(expectedReal, expectedImaginary, real, imaginary, 1e-10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AWarmTransformAllocatesNoManagedMemory()
|
||||
{
|
||||
var real = new double[256];
|
||||
var imaginary = new double[256];
|
||||
FastFourierTransform.Forward(real, imaginary);
|
||||
FastFourierTransform.Inverse(real, imaginary);
|
||||
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
for (var index = 0; index < 16; index++)
|
||||
{
|
||||
FastFourierTransform.Forward(real, imaginary);
|
||||
FastFourierTransform.Inverse(real, imaginary);
|
||||
}
|
||||
|
||||
Assert.Equal(0, GC.GetAllocatedBytesForCurrentThread() - before);
|
||||
}
|
||||
|
||||
static void AssertMaximumError(double[] expectedReal, double[] expectedImaginary, double[] actualReal, double[] actualImaginary, double tolerance)
|
||||
{
|
||||
var maximum = 0d;
|
||||
for (var index = 0; index < expectedReal.Length; index++)
|
||||
{
|
||||
var realError = Math.Abs(expectedReal[index] - actualReal[index]);
|
||||
var imaginaryError = Math.Abs(expectedImaginary[index] - actualImaginary[index]);
|
||||
maximum = Math.Max(maximum, Math.Max(realError, imaginaryError));
|
||||
}
|
||||
Assert.True(maximum <= tolerance, $"{maximum:R}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0-windows10.0.19041.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="10.0.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="xunit.v3" Version="4.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SpectralConvolution\SpectralConvolution.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
新しいイシューから参照
ユーザーをブロックする