From b666d48678f8fa269b7bc4e7362e030c72e81f31 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Wed, 4 Sep 2019 14:50:33 +0200 Subject: [PATCH] Added tests for static methods in the shader body --- tests/ComputeSharp.Tests/StaticMethodTests.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/ComputeSharp.Tests/StaticMethodTests.cs diff --git a/tests/ComputeSharp.Tests/StaticMethodTests.cs b/tests/ComputeSharp.Tests/StaticMethodTests.cs new file mode 100644 index 00000000..a93ddbeb --- /dev/null +++ b/tests/ComputeSharp.Tests/StaticMethodTests.cs @@ -0,0 +1,51 @@ +using System; +using System.Diagnostics.Contracts; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.Tests +{ + /// + /// A container for static methods to test + /// + public static class StaticMethodsContainer + { + [Pure] + public static float Square(float x) => x * x; + + [Pure] + public static Float4 Range(float x) => new Float4(x, x + 1, x + 2, x + 3); + } + + [TestClass] + [TestCategory("StaticMethodTests")] + public class StaticMethodTests + { + [TestMethod] + public void FloatToFloatFunc() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Gpu.Default.For(1, id => buffer[0] = StaticMethodsContainer.Square(3)); + + float[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0] - 9) < 0.0001f); + } + + [TestMethod] + public void FloatToFloat4Func() + { + using ReadWriteBuffer buffer = Gpu.Default.AllocateReadWriteBuffer(1); + + Gpu.Default.For(1, id => buffer[0] = StaticMethodsContainer.Range(3)); + + Float4[] result = buffer.GetData(); + + Assert.IsTrue(MathF.Abs(result[0].X - 3) < 0.0001f); + Assert.IsTrue(MathF.Abs(result[0].Y - 4) < 0.0001f); + Assert.IsTrue(MathF.Abs(result[0].Z - 5) < 0.0001f); + Assert.IsTrue(MathF.Abs(result[0].W - 6) < 0.0001f); + } + } +} +