Skip to content

Commit a2f57a6

Browse files
committed
PowerOfTwo
1 parent 3dcd2aa commit a2f57a6

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

src/libraries/System.Runtime.Numerics/tests/BigInteger/Rotate.cs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,39 @@ private static string Print(byte[] bytes)
302302
}
303303
}
304304

305-
public class RotateRightTest : RotateTestBase
305+
public class RotateLeftTest : RotateTestBase
306306
{
307-
public override string opstring => "bRotateRight";
307+
public override string opstring => "bRotateLeft";
308+
309+
[Fact]
310+
public void PowerOfTwo()
311+
{
312+
for (int i = 0; i < 32; i++)
313+
{
314+
foreach (int k in new int[] { 1, 2, 10 })
315+
{
316+
Assert.Equal(BigInteger.One << (32 * (k - 1) + i), BigInteger.RotateLeft(BigInteger.One << (32 * k + i), 32 * k));
317+
Assert.Equal((new BigInteger(uint.MaxValue << i)) << (32 * (k - 1)), BigInteger.RotateLeft(BigInteger.MinusOne << (32 * k + i), 32 * k));
318+
}
319+
}
320+
}
308321
}
309322

310-
public class RotateLeftTest : RotateTestBase
323+
public class RotateRightTest : RotateTestBase
311324
{
312-
public override string opstring => "bRotateLeft";
325+
public override string opstring => "bRotateRight";
326+
327+
[Fact]
328+
public void PowerOfTwo()
329+
{
330+
for (int i = 0; i < 32; i++)
331+
{
332+
foreach (int k in new int[] { 1, 2, 10 })
333+
{
334+
Assert.Equal(BigInteger.One << i, BigInteger.RotateRight(BigInteger.One << (32 * k + i), 32 * k));
335+
Assert.Equal(new BigInteger(uint.MaxValue << i), BigInteger.RotateRight(BigInteger.MinusOne << (32 * k + i), 32 * k));
336+
}
337+
}
338+
}
313339
}
314340
}

src/libraries/System.Runtime.Numerics/tests/BigInteger/op_rightshift.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,5 +376,18 @@ public static void LargeNegativeBigIntegerShiftTest()
376376
public class op_UnsignedRightshiftTest : op_rightshiftTestBase
377377
{
378378
public override string opstring => "b>>>";
379+
380+
[Fact]
381+
public void PowerOfTwo()
382+
{
383+
for (int i = 0; i < 32; i++)
384+
{
385+
foreach (int k in new int[] { 1, 2, 10 })
386+
{
387+
Assert.Equal(BigInteger.One << i, (BigInteger.One << (32 * k + i)) >>> (32 * k));
388+
Assert.Equal(new BigInteger(uint.MaxValue << i), (BigInteger.MinusOne << (32 * k + i)) >>> (32 * k));
389+
}
390+
}
391+
}
379392
}
380393
}

0 commit comments

Comments
 (0)