From 541f0b425cdd812e2766982ead1ff433c960076e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 5 Sep 2019 13:38:49 +0200 Subject: [PATCH] Added tests for captured functions --- tests/ComputeSharp.Tests/IntrinsicTests.cs | 2 +- .../StaticFunctionsTests.cs | 38 +++++++++++++++++++ .../ComputeSharp.Tests/StaticMethodsTests.cs | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/ComputeSharp.Tests/StaticFunctionsTests.cs diff --git a/tests/ComputeSharp.Tests/IntrinsicTests.cs b/tests/ComputeSharp.Tests/IntrinsicTests.cs index 7f0e4916..d6cd3365 100644 --- a/tests/ComputeSharp.Tests/IntrinsicTests.cs +++ b/tests/ComputeSharp.Tests/IntrinsicTests.cs @@ -4,7 +4,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ComputeSharp.Tests { [TestClass] - [TestCategory("IntrinsicTests")] + [TestCategory("Intrinsics")] public class IntrinsicTests { [TestMethod] diff --git a/tests/ComputeSharp.Tests/StaticFunctionsTests.cs b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs new file mode 100644 index 00000000..d10a5d5e --- /dev/null +++ b/tests/ComputeSharp.Tests/StaticFunctionsTests.cs @@ -0,0 +1,38 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests +{ + [TestClass] + [TestCategory("StaticFunctions")] + public class StaticFunctionsTests + { + [TestMethod] + public void FloatToFloatFunc() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Func square = StaticMethodsContainer.Square; + + Gpu.Default.For(1, id => buffer[0] = square(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } + + [TestMethod] + public void InternalFloatToFloatFunc() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Func square = StaticMethodsContainer.InternalSquare; + + Gpu.Default.For(1, id => buffer[0] = square(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } + } +} diff --git a/tests/ComputeSharp.Tests/StaticMethodsTests.cs b/tests/ComputeSharp.Tests/StaticMethodsTests.cs index a2123fd8..bcb0eebb 100644 --- a/tests/ComputeSharp.Tests/StaticMethodsTests.cs +++ b/tests/ComputeSharp.Tests/StaticMethodsTests.cs @@ -27,7 +27,7 @@ namespace ComputeSharp.Tests } [TestClass] - [TestCategory("StaticMethodsTests")] + [TestCategory("StaticMethods")] public class StaticMethodsTests { [TestMethod]