Skip to content

Commit

Permalink
+ LSR tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawkynt committed Aug 9, 2024
1 parent 325e011 commit eb1fd4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Corlib.Extensions/System/Math.T4.tt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static partial class MathEx {
public static <#=type#> LogicalShiftLeft(this <#=type#> @this, byte count) => (<#=type#>)ArithmeticShiftLeft((<#=(type=="sbyte"?"byte":"u"+type)#>)@this, count);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static <#=type#> LogicalShiftRight(this <#=type#> @this, byte count) => (<#=type#>)ArithmeticShiftRight(@this, count);
public static <#=type#> LogicalShiftRight(this <#=type#> @this, byte count) => (<#=type#>)ArithmeticShiftRight((<#=(type=="sbyte"?"byte":"u"+type)#>)@this, count);

<#}#>
<#foreach (var type in new[]{"byte","ushort","uint","ulong"}){#>
Expand Down
36 changes: 35 additions & 1 deletion Tests/Corlib.Tests/System/MathTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8589,7 +8589,41 @@ public void MinMax(byte[] values, int minValue, int maxValue) {
[TestCase(unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000001), 128, unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000000))]
public void LogicalShiftLeftLong(long inp, byte count, long expected) => Assert.AreEqual(expected, inp.LogicalShiftLeft(count));

// TODO: logic right shift
[Test]
[TestCase(unchecked((sbyte)0b00000001), 0, unchecked((sbyte)0b00000001))]
[TestCase(unchecked((sbyte)0b00000010), 1, unchecked((sbyte)0b00000001))]
[TestCase(unchecked((sbyte)0b10000000), 1, unchecked((sbyte)0b01000000))]
[TestCase(unchecked((sbyte)0b00000010), 2, unchecked((sbyte)0b00000000))]
[TestCase(unchecked((sbyte)0b10000000), 8, unchecked((sbyte)0b00000000))]
[TestCase(unchecked((sbyte)0b10000000), 16, unchecked((sbyte)0b00000000))]
public void LogicalShiftRightSByte(sbyte inp, byte count, sbyte expected) => Assert.AreEqual(expected, inp.LogicalShiftRight(count));

[Test]
[TestCase(unchecked((short)0b0000000000000001), 0, unchecked((short)0b0000000000000001))]
[TestCase(unchecked((short)0b0000000000000010), 1, unchecked((short)0b0000000000000001))]
[TestCase(unchecked((short)0b1000000000000000), 1, unchecked((short)0b0100000000000000))]
[TestCase(unchecked((short)0b0000000000000010), 2, unchecked((short)0b0000000000000000))]
[TestCase(unchecked((short)0b1000000000000000), 16, unchecked((short)0b0000000000000000))]
[TestCase(unchecked((short)0b1000000000000000), 32, unchecked((short)0b0000000000000000))]
public void LogicalShiftRightShort(short inp, byte count, short expected) => Assert.AreEqual(expected, inp.LogicalShiftRight(count));

[Test]
[TestCase(unchecked((int)0b00000000000000000000000000000001), 0, unchecked((int)0b00000000000000000000000000000001))]
[TestCase(unchecked((int)0b00000000000000000000000000000010), 1, unchecked((int)0b00000000000000000000000000000001))]
[TestCase(unchecked((int)0b10000000000000000000000000000000), 1, unchecked((int)0b01000000000000000000000000000000))]
[TestCase(unchecked((int)0b00000000000000000000000000000010), 2, unchecked((int)0b00000000000000000000000000000000))]
[TestCase(unchecked((int)0b10000000000000000000000000000000), 32, unchecked((int)0b00000000000000000000000000000000))]
[TestCase(unchecked((int)0b10000000000000000000000000000000), 64, unchecked((int)0b00000000000000000000000000000000))]
public void LogicalShiftRightInt(int inp, byte count, int expected) => Assert.AreEqual(expected, inp.LogicalShiftRight(count));

[Test]
[TestCase(unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000001), 0, unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000001))]
[TestCase(unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000010), 1, unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000001))]
[TestCase(unchecked((long)0b1000000000000000000000000000000000000000000000000000000000000000), 1, unchecked((long)0b0100000000000000000000000000000000000000000000000000000000000000))]
[TestCase(unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000010), 2, unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000000))]
[TestCase(unchecked((long)0b1000000000000000000000000000000000000000000000000000000000000000), 64, unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000000))]
[TestCase(unchecked((long)0b1000000000000000000000000000000000000000000000000000000000000000), 128, unchecked((long)0b0000000000000000000000000000000000000000000000000000000000000000))]
public void LogicalShiftRightLong(long inp, byte count, long expected) => Assert.AreEqual(expected, inp.LogicalShiftRight(count));

[Test]
[TestCase((byte)0b00000001, 0, (byte)0b00000001)]
Expand Down

0 comments on commit eb1fd4b

Please sign in to comment.