Skip to content

Commit

Permalink
Test unification (#176)
Browse files Browse the repository at this point in the history
* Renamed AssertHelperTests to Vec128/256

* Unified (some) tests between Base64 and Base64Url
  • Loading branch information
gfoidl authored Oct 9, 2022
1 parent 0afc2ce commit 0727aea
Show file tree
Hide file tree
Showing 37 changed files with 625 additions and 2,097 deletions.
2 changes: 1 addition & 1 deletion source/gfoidl.Base64/Internal/Encodings/Base64Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace gfoidl.Base64.Internal;

internal readonly partial struct Base64Encoding : IBase64Encoding
internal readonly struct Base64Encoding : IBase64Encoding
{
public static bool HasPadding { get; } = true;
//-------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace gfoidl.Base64.Internal;

internal readonly partial struct Base64UrlEncoding : IBase64Encoding
internal readonly struct Base64UrlEncoding : IBase64Encoding
{
public static bool HasPadding { get; } = false;
//-------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/gfoidl.Base64.Tests/Base64Tests/Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void Default___base64_is_used()
public void Default_with_buffers___base64_is_used()
{
byte[] data = { 0x00 };
const int encodedLength = 4;
Span<T> base64 = stackalloc T[encodedLength];
const int EncodedLength = 4;
Span<T> base64 = stackalloc T[EncodedLength];
OperationStatus status;
int consumed, written;

Expand Down
4 changes: 2 additions & 2 deletions tests/gfoidl.Base64.Tests/Base64Tests/Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void Url___base64Url_is_used()
public void Url_with_buffers___base64Url_is_used()
{
byte[] data = { 0x00 };
const int encodedLength = 2;
Span<T> base64 = stackalloc T[encodedLength];
const int EncodedLength = 2;
Span<T> base64 = stackalloc T[EncodedLength];
OperationStatus status;
int consumed, written;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class AssertRead
private static readonly byte[] s_source = Enumerable.Range(0, 100).Select(i => (byte)i).ToArray();
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_read_and_srcLength_is_16()
public void Vector128_byte_read_and_srcLength_is_16()
{
Span<byte> source = GetSource(16);
ref byte src = ref source[0];
Expand All @@ -25,7 +25,7 @@ public void Sse_byte_read_and_srcLength_is_16()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_read_and_srcLength_is_8()
public void Vector128_char_read_and_srcLength_is_8()
{
Span<char> source = MemoryMarshal.Cast<byte, char>(GetSource(16));
ref char src = ref source[0];
Expand All @@ -35,7 +35,7 @@ public void Sse_char_read_and_srcLength_is_8()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_read_and_srcLength_is_17()
public void Vector128_byte_read_and_srcLength_is_17()
{
Span<byte> source = GetSource(17);
ref byte src = ref source[0];
Expand All @@ -45,7 +45,7 @@ public void Sse_byte_read_and_srcLength_is_17()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_read_and_srcLength_is_9()
public void Vector128_char_read_and_srcLength_is_9()
{
Span<char> source = MemoryMarshal.Cast<byte, char>(GetSource(17));
ref char src = ref source[0];
Expand All @@ -55,7 +55,7 @@ public void Sse_char_read_and_srcLength_is_9()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_read_and_srcLength_is_15___throws_InvalidOperation()
public void Vector128_byte_read_and_srcLength_is_15___throws_InvalidOperation()
{
Assert.Throws<InvalidOperationException>(() =>
{
Expand All @@ -68,7 +68,7 @@ public void Sse_byte_read_and_srcLength_is_15___throws_InvalidOperation()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_read_and_srcLength_is_7___throws_InvalidOperation()
public void Vector128_char_read_and_srcLength_is_7___throws_InvalidOperation()
{
Assert.Throws<InvalidOperationException>(() =>
{
Expand All @@ -81,7 +81,7 @@ public void Sse_char_read_and_srcLength_is_7___throws_InvalidOperation()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_read_with_offset_and_srcLength_is_16_plus_offset()
public void Vector128_byte_read_with_offset_and_srcLength_is_16_plus_offset()
{
Span<byte> source = GetSource(16 + 3);
ref byte src = ref source[0];
Expand All @@ -93,7 +93,7 @@ public void Sse_byte_read_with_offset_and_srcLength_is_16_plus_offset()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_read_with_offset_and_srcLength_is_8_plus_offset()
public void Vector128_char_read_with_offset_and_srcLength_is_8_plus_offset()
{
Span<char> source = MemoryMarshal.Cast<byte, char>(GetSource(16 + 6));
ref char src = ref source[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace gfoidl.Base64.Tests.Internal.AssertHelperTests;
public partial class AssertRead
{
[Test]
public void Avx_byte_read_and_srcLength_is_32()
public void Vector256_byte_read_and_srcLength_is_32()
{
Span<byte> source = GetSource(32);
ref byte src = ref source[0];
Expand All @@ -22,7 +22,7 @@ public void Avx_byte_read_and_srcLength_is_32()
}
//-------------------------------------------------------------------------
[Test]
public void Avx_byte_read_and_srcLength_is_33()
public void Vector256_byte_read_and_srcLength_is_33()
{
Span<byte> source = GetSource(33);
ref byte src = ref source[0];
Expand All @@ -32,7 +32,7 @@ public void Avx_byte_read_and_srcLength_is_33()
}
//-------------------------------------------------------------------------
[Test]
public void Avx_byte_read_and_srcLength_is_31___throws_InvalidOperation()
public void Vector256_byte_read_and_srcLength_is_31___throws_InvalidOperation()
{
Assert.Throws<InvalidOperationException>(() =>
{
Expand All @@ -45,7 +45,7 @@ public void Avx_byte_read_and_srcLength_is_31___throws_InvalidOperation()
}
//-------------------------------------------------------------------------
[Test]
public void Avx_byte_read_with_offset_and_srcLength_is_32_plus_offset()
public void Vector256_byte_read_with_offset_and_srcLength_is_32_plus_offset()
{
Span<byte> source = GetSource(32 + 3);
ref byte src = ref source[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
using System.Runtime.Intrinsics;
using gfoidl.Base64.Internal;


namespace gfoidl.Base64.Tests.Internal.AssertHelperTests;

[TestFixture]
public partial class AssertWrite
{
private static readonly byte[] _dest = Enumerable.Range(0, 100).Select(i => (byte)i).ToArray();
private static readonly byte[] s_dest = Enumerable.Range(0, 100).Select(i => (byte)i).ToArray();
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_write_and_destLength_is_16()
public void Vector128_byte_write_and_destLength_is_16()
{
Span<byte> destination = GetDestination(16);
ref byte dest = ref destination[0];
Expand All @@ -26,7 +25,7 @@ public void Sse_byte_write_and_destLength_is_16()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_write_and_destLength_is_8()
public void Vector128_char_write_and_destLength_is_8()
{
Span<char> destination = MemoryMarshal.Cast<byte, char>(GetDestination(16));
ref char dest = ref destination[0];
Expand All @@ -36,7 +35,7 @@ public void Sse_char_write_and_destLength_is_8()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_write_and_srcLength_is_17()
public void Vector128_byte_write_and_srcLength_is_17()
{
Span<byte> destination = GetDestination(17);
ref byte dest = ref destination[0];
Expand All @@ -46,7 +45,7 @@ public void Sse_byte_write_and_srcLength_is_17()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_write_and_destLength_is_9()
public void Vector128_char_write_and_destLength_is_9()
{
Span<char> destination = MemoryMarshal.Cast<byte, char>(GetDestination(17));
ref char dest = ref destination[0];
Expand All @@ -56,7 +55,7 @@ public void Sse_char_write_and_destLength_is_9()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_write_and_srcLength_is_15___throws_InvalidOperation()
public void Vector128_byte_write_and_srcLength_is_15___throws_InvalidOperation()
{
Assert.Throws<InvalidOperationException>(() =>
{
Expand All @@ -69,7 +68,7 @@ public void Sse_byte_write_and_srcLength_is_15___throws_InvalidOperation()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_write_and_srcLength_is_7___throws_InvalidOperation()
public void Vector128_char_write_and_srcLength_is_7___throws_InvalidOperation()
{
Assert.Throws<InvalidOperationException>(() =>
{
Expand All @@ -82,7 +81,7 @@ public void Sse_char_write_and_srcLength_is_7___throws_InvalidOperation()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_byte_write_with_offset_and_srcLength_is_16_plus_offset()
public void Vector128_byte_write_with_offset_and_srcLength_is_16_plus_offset()
{
Span<byte> destination = GetDestination(16 + 3);
ref byte dest = ref destination[0];
Expand All @@ -94,7 +93,7 @@ public void Sse_byte_write_with_offset_and_srcLength_is_16_plus_offset()
}
//-------------------------------------------------------------------------
[Test]
public void Sse_char_write_with_offset_and_srcLength_is_8_plus_offset()
public void Vector128_char_write_with_offset_and_srcLength_is_8_plus_offset()
{
Span<char> destination = MemoryMarshal.Cast<byte, char>(GetDestination(16 + 6));
ref char dest = ref destination[0];
Expand All @@ -103,7 +102,7 @@ public void Sse_char_write_with_offset_and_srcLength_is_8_plus_offset()
dest.AssertWrite<Vector128<sbyte>, char>(ref destStart, destination.Length);
}
//-------------------------------------------------------------------------
private static Span<byte> GetDestination(int size) => _dest.AsSpan(0, size);
private static Span<byte> GetDestination(int size) => s_dest.AsSpan(0, size);
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
using System.Runtime.Intrinsics;
using gfoidl.Base64.Internal;


namespace gfoidl.Base64.Tests.Internal.AssertHelperTests;

[TestFixture]
public partial class AssertWrite
{
[Test]
public void Avx_byte_write_and_destLength_is_32()
public void Vector256_byte_write_and_destLength_is_32()
{
Span<byte> destination = GetDestination(32);
ref byte dest = ref destination[0];
Expand All @@ -23,7 +22,7 @@ public void Avx_byte_write_and_destLength_is_32()
}
//-------------------------------------------------------------------------
[Test]
public void Avx_byte_write_and_srcLength_is_33()
public void Vector256_byte_write_and_srcLength_is_33()
{
Span<byte> destination = GetDestination(33);
ref byte dest = ref destination[0];
Expand All @@ -33,7 +32,7 @@ public void Avx_byte_write_and_srcLength_is_33()
}
//-------------------------------------------------------------------------
[Test]
public void Avx_byte_write_and_srcLength_is_31___throws_InvalidOperation()
public void Vector256_byte_write_and_srcLength_is_31___throws_InvalidOperation()
{
Assert.Throws<InvalidOperationException>(() =>
{
Expand All @@ -46,7 +45,7 @@ public void Avx_byte_write_and_srcLength_is_31___throws_InvalidOperation()
}
//-------------------------------------------------------------------------
[Test]
public void Avx_byte_write_with_offset_and_srcLength_is_32_plus_offset()
public void Vector256_byte_write_with_offset_and_srcLength_is_32_plus_offset()
{
Span<byte> destination = GetDestination(32 + 3);
ref byte dest = ref destination[0];
Expand Down
Loading

0 comments on commit 0727aea

Please sign in to comment.