Seed HLSL-shaped math library
This commit is contained in:
commit
38b79a8d89
12 changed files with 366 additions and 0 deletions
20
tests/CultMath.Tests/CultMath.Tests.csproj
Normal file
20
tests/CultMath.Tests/CultMath.Tests.csproj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="xunit.v3" Version="3.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\CultMath\CultMath.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
38
tests/CultMath.Tests/MathTests.cs
Normal file
38
tests/CultMath.Tests/MathTests.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using CultMath;
|
||||
using Xunit;
|
||||
|
||||
namespace CultMath.Tests;
|
||||
|
||||
public sealed class MathTests
|
||||
{
|
||||
[Fact]
|
||||
public void FracMatchesShaderStylePositiveAndNegativeValues()
|
||||
{
|
||||
Assert.Equal(0.25f, math.frac(1.25f));
|
||||
Assert.Equal(0.75f, math.frac(-1.25f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VectorOperationsAreComponentWise()
|
||||
{
|
||||
var value = new float3(1.0f, 2.0f, 3.0f) * new float3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
Assert.Equal(new float3(4.0f, 10.0f, 18.0f), value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NormalizeProducesUnitLength()
|
||||
{
|
||||
var value = math.normalize(new float3(3.0f, 4.0f, 0.0f));
|
||||
|
||||
Assert.Equal(1.0f, math.length(value), precision: 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SmoothstepUsesHermiteRamp()
|
||||
{
|
||||
Assert.Equal(0.0f, math.smoothstep(0.0f, 1.0f, -1.0f));
|
||||
Assert.Equal(0.5f, math.smoothstep(0.0f, 1.0f, 0.5f), precision: 5);
|
||||
Assert.Equal(1.0f, math.smoothstep(0.0f, 1.0f, 2.0f));
|
||||
}
|
||||
}
|
||||
Reference in a new issue