Skip to content

Commit

Permalink
Merge branch 'master' into documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharylayne authored Aug 27, 2024
2 parents 4088232 + 06547b5 commit efd87c1
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
namespace ConstTypeArgs.Core.Tests;

public partial class ConstTypeArgInterfaceTests
{
public readonly struct IntConstTypeArg : IConstTypeArg<int, IntConstTypeArg>
{ public static int Value => 42; }

public readonly struct UintConstTypeArg : IConstTypeArg<uint, UintConstTypeArg>
{ public static uint Value => 42u; }

public readonly struct FloatConstTypeArg : IConstTypeArg<float, FloatConstTypeArg>
{ public static float Value => 42.0f; }

public readonly struct StringArg : IConstTypeArg<string, StringArg>
{ public static string Value => "Hello, World!"; }

public readonly struct IntArrayArg : K_Array<int>
{ public static int[] Value => [1, 2, 3]; }

public readonly struct StringArrayArg : K_Array<string>
{ public static string[] Value => ["A", "B", "C"]; }

public readonly struct StringClassArg : K_Class<string>
{ public static string Value => "Class String!"; }

public readonly struct ObjectClassArg : K_Class<object>
{ public static object Value => new(); }

public readonly struct ActionDelegateArg : K_Delegate<Action>
{ public static Action Value => () => Console.WriteLine("Action delegate executed!"); }

public readonly struct FuncDelegateArg : K_Delegate<Func<int>>
{ public static Func<int> Value => () => 42; }

public enum TestEnum { A, B, C }

public readonly struct EnumArg : K_Enum<TestEnum>
{ public static TestEnum Value => TestEnum.B; }

public readonly struct MulticastDelegateArg : K_MulticastDelegate<Action>
{ public static Action Value => () => Console.WriteLine("Multicast delegate executed!"); }

public readonly struct IntNumberArg : K_Number<int>
{ public static int Value => 10; }

public readonly struct FloatNumberArg : K_Number<float>
{ public static float Value => 3.14f; }

public readonly struct StringReadOnlyMemoryArg : K_ReadOnlyMemory<string>
{ public static ReadOnlyMemory<string> Value => new[] { "Hello", "World" }; }

public readonly struct StringReadOnlyMemoryArrayArg : K_ReadOnlyMemoryArray<string>
{
public static ReadOnlyMemory<string>[][] Value =>
[
[ new ReadOnlyMemory<string>(["Hello", "World"]) ],
[ new ReadOnlyMemory<string>(["World", "Hello"]) ]
];
}

public readonly struct StringReadOnlyMemoryTArrayArg : K_ReadOnlyMemoryT_Array<string>
{ public static ReadOnlyMemory<string[]> 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<int>
{ public static int Value => 100; }

public readonly struct FloatUnmanagedArg : K_Unmanaged<float>
{ public static float Value => 1.23f; }
}
55 changes: 55 additions & 0 deletions Tests/ConstTypeArgs.Core.Tests/ConstTypeArgInterfaceTests.cs
Original file line number Diff line number Diff line change
@@ -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<int>);

// Act & Assert
type.Should().Implement<IConstTypeArg>();
}

[Fact]
public void IntConstTypeArg_ShouldImplement_IConstTypeArgT()
{
// Arrange
var type = typeof(IntConstTypeArg);

// Act
var implementsInterface = typeof(IConstTypeArg<int>).IsAssignableFrom(type);

// Assert
implementsInterface.Should().BeTrue("IntConstTypeArg should implement IConstTypeArg<int>");
}

[Fact]
public void FakeConstTypeArg_ShouldImplement_IConstTypeArgT()
{
// Arrange
var type = typeof(IntConstTypeArg);

// Act
var implementsInterface = typeof(IConstTypeArg<int>).IsAssignableFrom(type);

// Assert
implementsInterface.Should().BeTrue("FakeConstTypeArg should implement IConstTypeArg<int>");
}

[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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
<Using Include="ConstTypeArgs" />
<Using Include="ConstTypeArgs.Core" />
<Using Include="FluentAssertions" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

Expand Down

0 comments on commit efd87c1

Please sign in to comment.