Skip to content

Commit

Permalink
Add support for index and range
Browse files Browse the repository at this point in the history
  • Loading branch information
afxres committed Jul 25, 2024
1 parent bf01877 commit 14a201a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mikodev.Binary.Tests.Features;
namespace Mikodev.Binary.Tests.Converters.Primitive;

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace Mikodev.Binary.Tests.Features;
namespace Mikodev.Binary.Tests.Converters.Primitive;

using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

public class IntegrationTests
public class NativeEndianOrLittleEndianDataTests
{
public static IEnumerable<object[]> SimpleObjectData =>
[
Expand Down Expand Up @@ -45,6 +45,14 @@ public void ConverterBasicInfo(int length, object data)
[double.NegativeInfinity],
];

public static IEnumerable<object[]> IndexData()
{
yield return new object[] { Index.Start };
yield return new object[] { Index.End };
yield return new object[] { Index.FromStart(2) };
yield return new object[] { Index.FromEnd(3) };
}

public static IEnumerable<object[]> DateOnlyData =>
[
[DateOnly.MinValue],
Expand Down Expand Up @@ -100,6 +108,7 @@ public void ConverterBasicInfo(int length, object data)

[Theory(DisplayName = "Encode Decode")]
[MemberData(nameof(NumberData))]
[MemberData(nameof(IndexData))]
[MemberData(nameof(DateOnlyData))]
[MemberData(nameof(DateTimeOffsetData))]
[MemberData(nameof(DateTimeData))]
Expand Down Expand Up @@ -127,6 +136,7 @@ public void EncodeDecode<T>(T item)

[Theory(DisplayName = "Encode Decode Auto")]
[MemberData(nameof(NumberData))]
[MemberData(nameof(IndexData))]
[MemberData(nameof(DateOnlyData))]
[MemberData(nameof(DateTimeOffsetData))]
[MemberData(nameof(DateTimeData))]
Expand All @@ -153,6 +163,7 @@ public void EncodeDecodeAuto<T>(T item)

[Theory(DisplayName = "Encode Decode With Length Prefix")]
[MemberData(nameof(NumberData))]
[MemberData(nameof(IndexData))]
[MemberData(nameof(DateOnlyData))]
[MemberData(nameof(DateTimeOffsetData))]
[MemberData(nameof(DateTimeData))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mikodev.Binary.Tests.Features;
namespace Mikodev.Binary.Tests.Converters.Primitive;

using System;
using System.Collections.Generic;
Expand All @@ -8,7 +8,7 @@
using System.Runtime.InteropServices;
using Xunit;

public class EndiannessTests
public class NativeEndianOrLittleEndianInfoTests
{
private delegate T Decode<T>(ref byte source);

Expand Down Expand Up @@ -53,9 +53,18 @@ public struct Block64 { }
[8, 3.0],
];

public static IEnumerable<object[]> IndexData()
{
yield return new object[] { 4, Index.Start };
yield return new object[] { 4, Index.End };
yield return new object[] { 4, Index.FromStart(1) };
yield return new object[] { 4, Index.FromEnd(1) };
}

[Theory(DisplayName = "Fallback Converter Info")]
[MemberData(nameof(EnumData))]
[MemberData(nameof(NumberData))]
[MemberData(nameof(IndexData))]
public void FallbackConverterBasicInfo<T>(int length, T data)
{
var generator = Generator.CreateDefault();
Expand All @@ -71,6 +80,7 @@ public void FallbackConverterBasicInfo<T>(int length, T data)
[Theory(DisplayName = "Internal Native Endian Converter Info")]
[MemberData(nameof(EnumData))]
[MemberData(nameof(NumberData))]
[MemberData(nameof(IndexData))]
public void InternalNativeEndianConverterInfo<T>(int length, T data)
{
var creatorName = typeof(T).IsEnum ? "DetectEndianEnumConverterCreator" : "DetectEndianConverterCreator";
Expand All @@ -89,6 +99,7 @@ public void InternalNativeEndianConverterInfo<T>(int length, T data)
[Theory(DisplayName = "Internal Little Endian Converter Info")]
[MemberData(nameof(EnumData))]
[MemberData(nameof(NumberData))]
[MemberData(nameof(IndexData))]
public void InternalLittleEndianConverterInfo<T>(int length, T data)
{
var creatorName = typeof(T).IsEnum ? "DetectEndianEnumConverterCreator" : "DetectEndianConverterCreator";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mikodev.Binary.Tests.Converters.Numerics;
namespace Mikodev.Binary.Tests.Converters.Primitive;

using Mikodev.Binary.Tests.Contexts;
using Mikodev.Binary.Tests.Internal;
Expand All @@ -10,8 +10,17 @@
using System.Runtime.InteropServices;
using Xunit;

public class ConverterIntegrationTests
public class NativeEndianOrRepeatLittleEndianDataTests
{
public static IEnumerable<object[]> RangeData()
{
yield return new object[] { Range.All };
yield return new object[] { Range.StartAt(Index.FromStart(2)) };
yield return new object[] { Range.StartAt(Index.FromEnd(3)) };
yield return new object[] { Range.EndAt(Index.FromStart(4)) };
yield return new object[] { Range.EndAt(Index.FromEnd(5)) };
}

public static IEnumerable<object[]> ComplexData()
{
yield return new object[] { Complex.Zero };
Expand Down Expand Up @@ -77,6 +86,7 @@ public static IEnumerable<object[]> Vector4Data()
}

[Theory(DisplayName = "Encode Decode")]
[MemberData(nameof(RangeData))]
[MemberData(nameof(ComplexData))]
[MemberData(nameof(Matrix3x2Data))]
[MemberData(nameof(Matrix4x4Data))]
Expand All @@ -101,6 +111,7 @@ public void EncodeDecode<T>(T data) where T : unmanaged
}

[Theory(DisplayName = "Encode Decode Multiple")]
[MemberData(nameof(RangeData))]
[MemberData(nameof(ComplexData))]
[MemberData(nameof(Matrix3x2Data))]
[MemberData(nameof(Matrix4x4Data))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Mikodev.Binary.Tests.Converters.Numerics;
namespace Mikodev.Binary.Tests.Converters.Primitive;

using Mikodev.Binary.Tests.Internal;
using System;
Expand All @@ -8,13 +8,14 @@
using System.Reflection;
using Xunit;

public class ConverterBasicTests
public class NativeEndianOrRepeatLittleEndianInfoTests
{
[Fact(DisplayName = "Shared Converters With Known Types")]
public void SharedConverters()
{
var knownTypes = new[]
{
typeof(Range),
typeof(Complex),
typeof(Matrix3x2),
typeof(Matrix4x4),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ static void RegisterRepeat<T, E>(Dictionary<Type, ConverterPair> dictionary) whe
Register<float>(dictionary);
Register<double>(dictionary);
Register<Half>(dictionary);
Register<Index>(dictionary);
Register<BitVector32>(dictionary);
Register<Int128>(dictionary);
Register<UInt128>(dictionary);

RegisterRepeat<Range, int>(dictionary);
RegisterRepeat<Complex, double>(dictionary);
RegisterRepeat<Matrix3x2, float>(dictionary);
RegisterRepeat<Matrix4x4, float>(dictionary);
Expand Down

0 comments on commit 14a201a

Please sign in to comment.