Skip to content

Commit

Permalink
+ tests for rotate right
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawkynt committed Aug 6, 2024
1 parent bc01ee4 commit 310ac5f
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Tests/Corlib.Tests/System/MathTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8591,7 +8591,41 @@ public void MinMax(byte[] values, int minValue, int maxValue) {
[TestCase((ulong)0b0000000000000000000000000000000000000000000000000000000000000001, 64, (ulong)0b0000000000000000000000000000000000000000000000000000000000000001)]
[TestCase((ulong)0b0000000000000000000000000000000000000000000000000000000000000001, 128, (ulong)0b0000000000000000000000000000000000000000000000000000000000000001)]
public void RotateLeftQWord(ulong inp, byte count, ulong expected) => Assert.AreEqual(expected, inp.RotateLeft(count));

// TODO: right rotate

[Test]
[TestCase((byte)0b00000001, 0, (byte)0b00000001)]
[TestCase((byte)0b00000010, 1, (byte)0b00000001)]
[TestCase((byte)0b10000001, 1, (byte)0b11000000)]
[TestCase((byte)0b10000000, 7, (byte)0b00000001)]
[TestCase((byte)0b10000000, 8, (byte)0b10000000)]
[TestCase((byte)0b10000000, 16, (byte)0b10000000)]
public void RotateRightByte(byte inp, byte count, byte expected) => Assert.AreEqual(expected, inp.RotateRight(count));

[Test]
[TestCase((ushort)0b0000000000000001, 0, (ushort)0b0000000000000001)]
[TestCase((ushort)0b0000000000000010, 1, (ushort)0b0000000000000001)]
[TestCase((ushort)0b1000000000000001, 1, (ushort)0b1100000000000000)]
[TestCase((ushort)0b1000000000000000, 15, (ushort)0b0000000000000001)]
[TestCase((ushort)0b1000000000000000, 16, (ushort)0b1000000000000000)]
[TestCase((ushort)0b1000000000000000, 32, (ushort)0b1000000000000000)]
public void RotateRightWord(ushort inp, byte count, ushort expected) => Assert.AreEqual(expected, inp.RotateRight(count));

[Test]
[TestCase((uint)0b00000000000000000000000000000001, 0, (uint)0b00000000000000000000000000000001)]
[TestCase((uint)0b00000000000000000000000000000010, 1, (uint)0b00000000000000000000000000000001)]
[TestCase((uint)0b10000000000000000000000000000001, 1, (uint)0b11000000000000000000000000000000)]
[TestCase((uint)0b10000000000000000000000000000000, 31, (uint)0b00000000000000000000000000000001)]
[TestCase((uint)0b10000000000000000000000000000000, 32, (uint)0b10000000000000000000000000000000)]
[TestCase((uint)0b10000000000000000000000000000000, 64, (uint)0b10000000000000000000000000000000)]
public void RotateRightDWord(uint inp, byte count, uint expected) => Assert.AreEqual(expected, inp.RotateRight(count));

[Test]
[TestCase((ulong)0b0000000000000000000000000000000000000000000000000000000000000001, 0, (ulong)0b0000000000000000000000000000000000000000000000000000000000000001)]
[TestCase((ulong)0b0000000000000000000000000000000000000000000000000000000000000010, 1, (ulong)0b0000000000000000000000000000000000000000000000000000000000000001)]
[TestCase((ulong)0b1000000000000000000000000000000000000000000000000000000000000001, 1, (ulong)0b1100000000000000000000000000000000000000000000000000000000000000)]
[TestCase((ulong)0b1000000000000000000000000000000000000000000000000000000000000000, 63, (ulong)0b0000000000000000000000000000000000000000000000000000000000000001)]
[TestCase((ulong)0b1000000000000000000000000000000000000000000000000000000000000000, 64, (ulong)0b1000000000000000000000000000000000000000000000000000000000000000)]
[TestCase((ulong)0b1000000000000000000000000000000000000000000000000000000000000000, 128, (ulong)0b1000000000000000000000000000000000000000000000000000000000000000)]
public void RotateRightQWord(ulong inp, byte count, ulong expected) => Assert.AreEqual(expected, inp.RotateRight(count));

}

0 comments on commit 310ac5f

Please sign in to comment.