diff --git a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs index d10a5d5e..5a5ad8b7 100644 --- a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs +++ b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs @@ -34,5 +34,46 @@ namespace ComputeSharp.Tests Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); } + + [TestMethod] + public void ChangingFuncsFromSameMethod() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Func func = StaticMethodsContainer.Square; + + Gpu.Default.For(1, id => buffer[0] = func(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + + func = StaticMethodsContainer.Negate; + + Gpu.Default.For(1, id => buffer[0] = func(3)); + + result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] + 3) < 0.0001f); + } + + [TestMethod] + public void ChangingFuncsFromExternalMethod() + { + MethodRunner(StaticMethodsContainer.Square, 3, 9); + + MethodRunner(StaticMethodsContainer.Negate, 3, -3); + } + + private void MethodRunner(Func func, float input, float expected) + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Gpu.Default.For(1, id => buffer[0] = func(input)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - expected) < 0.0001f); + } } } diff --git a/tests/ComputeSharp.Tests/StaticMethodsTests.cs b/tests/ComputeSharp.Tests/StaticMethodsTests.cs index bcb0eebb..3efd02a7 100644 --- a/tests/ComputeSharp.Tests/StaticMethodsTests.cs +++ b/tests/ComputeSharp.Tests/StaticMethodsTests.cs @@ -12,6 +12,9 @@ namespace ComputeSharp.Tests [Pure] public static float Square(float x) => x * x; + [Pure] + public static float Negate(float x) => -x; + [Pure] internal static float InternalSquare(float x) => x * x;