From 15dbf401ced634a81760ae0a8a2d9fa4c949faa2 Mon Sep 17 00:00:00 2001 From: zacharylayne Date: Tue, 27 Aug 2024 11:02:22 -0700 Subject: [PATCH] First Commit of ConstTypeArgs.Core Tests First commit. Added all test types. Implemented a handful of tests. More TBD. --- .../ConstTypeArgInterfaceTests.TestTypes.cs | 75 +++++++++++++++++++ .../ConstTypeArgInterfaceTests.cs | 55 ++++++++++++++ .../ConstTypeArgs.Core.Tests.csproj | 23 ++++++ 3 files changed, 153 insertions(+) create mode 100644 Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.TestTypes.cs create mode 100644 Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.cs create mode 100644 Tests/ConstTypeArgs.Core.Tests/ConstTypeArgs.Core.Tests.csproj diff --git a/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.TestTypes.cs b/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.TestTypes.cs new file mode 100644 index 0000000..816d3d8 --- /dev/null +++ b/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.TestTypes.cs @@ -0,0 +1,75 @@ +namespace ConstTypeArgs.Core.Tests; + +public partial class ConstTypeArgInterfaceTests +{ + public readonly struct IntConstTypeArg : IConstTypeArg + { public static int Value => 42; } + + public readonly struct UintConstTypeArg : IConstTypeArg + { public static uint Value => 42u; } + + public readonly struct FloatConstTypeArg : IConstTypeArg + { public static float Value => 42.0f; } + + public readonly struct StringArg : IConstTypeArg + { public static string Value => "Hello, World!"; } + + public readonly struct IntArrayArg : K_Array + { public static int[] Value => [1, 2, 3]; } + + public readonly struct StringArrayArg : K_Array + { public static string[] Value => ["A", "B", "C"]; } + + public readonly struct StringClassArg : K_Class + { public static string Value => "Class String!"; } + + public readonly struct ObjectClassArg : K_Class + { public static object Value => new(); } + + public readonly struct ActionDelegateArg : K_Delegate + { public static Action Value => () => Console.WriteLine("Action delegate executed!"); } + + public readonly struct FuncDelegateArg : K_Delegate> + { public static Func Value => () => 42; } + + public enum TestEnum { A, B, C } + + public readonly struct EnumArg : K_Enum + { public static TestEnum Value => TestEnum.B; } + + public readonly struct MulticastDelegateArg : K_MulticastDelegate + { public static Action Value => () => Console.WriteLine("Multicast delegate executed!"); } + + public readonly struct IntNumberArg : K_Number + { public static int Value => 10; } + + public readonly struct FloatNumberArg : K_Number + { public static float Value => 3.14f; } + + public readonly struct StringReadOnlyMemoryArg : K_ReadOnlyMemory + { public static ReadOnlyMemory Value => new[] { "Hello", "World" }; } + + public readonly struct StringReadOnlyMemoryArrayArg : K_ReadOnlyMemoryArray + { + public static ReadOnlyMemory[][] Value => + [ + [ new ReadOnlyMemory(["Hello", "World"]) ], + [ new ReadOnlyMemory(["World", "Hello"]) ] + ]; + } + + public readonly struct StringReadOnlyMemoryTArrayArg : K_ReadOnlyMemoryT_Array + { public static ReadOnlyMemory Value => new[] { new[] { "Hello", "World" } }; } + + public readonly struct PointStructArg : K_Struct<(int X, int Y)> + { public static (int X, int Y) Value => (10, 20); } + + public readonly struct RectangleStructArg : K_Struct<(int Width, int Height)> + { public static (int Width, int Height) Value => (100, 200); } + + public readonly struct IntUnmanagedArg : K_Unmanaged + { public static int Value => 100; } + + public readonly struct FloatUnmanagedArg : K_Unmanaged + { public static float Value => 1.23f; } +} diff --git a/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.cs b/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.cs new file mode 100644 index 0000000..82a868b --- /dev/null +++ b/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.cs @@ -0,0 +1,55 @@ +using FluentAssertions; + +namespace ConstTypeArgs.Core.Tests; + +public partial class ConstTypeArgInterfaceTests +{ + [Fact] + public void IConstTypeArgT_ShouldImplement_IConstTypeArg() + { + // Arrange + var type = typeof(IConstTypeArg); + + // Act & Assert + type.Should().Implement(); + } + + [Fact] + public void IntConstTypeArg_ShouldImplement_IConstTypeArgT() + { + // Arrange + var type = typeof(IntConstTypeArg); + + // Act + var implementsInterface = typeof(IConstTypeArg).IsAssignableFrom(type); + + // Assert + implementsInterface.Should().BeTrue("IntConstTypeArg should implement IConstTypeArg"); + } + + [Fact] + public void FakeConstTypeArg_ShouldImplement_IConstTypeArgT() + { + // Arrange + var type = typeof(IntConstTypeArg); + + // Act + var implementsInterface = typeof(IConstTypeArg).IsAssignableFrom(type); + + // Assert + implementsInterface.Should().BeTrue("FakeConstTypeArg should implement IConstTypeArg"); + } + + [Fact] + public void IntConstTypeArg_Value_ShouldReturnExpectedValue() + { + // Arrange + const int expectedValue = 42; + + // Act + var value = IntConstTypeArg.Value; + + // Assert + value.Should().Be(expectedValue, "IntConstTypeArg.Value should return 42"); + } +} diff --git a/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgs.Core.Tests.csproj b/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgs.Core.Tests.csproj new file mode 100644 index 0000000..9c5b30a --- /dev/null +++ b/Tests/ConstTypeArgs.Core.Tests/ConstTypeArgs.Core.Tests.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + +