mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-15 08:25:41 +00:00
68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using X10D.Numerics;
|
|
|
|
namespace X10D.Tests.Numerics;
|
|
|
|
[TestClass]
|
|
public class ByteTests
|
|
{
|
|
[TestMethod]
|
|
public void RotateLeft_ShouldRotateCorrectly()
|
|
{
|
|
const byte value = 181; // 10110101
|
|
const byte expected = 91; // 01011011
|
|
|
|
Assert.AreEqual(value, value.RotateLeft(0));
|
|
Assert.AreEqual(expected, value.RotateLeft(4));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RotateLeft_ShouldModForLargeCount()
|
|
{
|
|
const byte value = 181; // 10110101
|
|
Assert.AreEqual(value, value.RotateLeft(8));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RotateRight_ShouldRotateCorrectly()
|
|
{
|
|
const byte value = 181; // 10110101
|
|
const byte expected = 91; // 01011011
|
|
|
|
Assert.AreEqual(value, value.RotateRight(0));
|
|
Assert.AreEqual(expected, value.RotateRight(4));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RotateRight_ShouldModForLargeCount()
|
|
{
|
|
const byte value = 181; // 10110101
|
|
Assert.AreEqual(value, value.RotateRight(8));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RoundUpToPowerOf2_ShouldReturnRoundedValue_GivenValue()
|
|
{
|
|
Assert.AreEqual(4, ((byte)3).RoundUpToPowerOf2());
|
|
Assert.AreEqual(8, ((byte)5).RoundUpToPowerOf2());
|
|
Assert.AreEqual(8, ((byte)6).RoundUpToPowerOf2());
|
|
Assert.AreEqual(8, ((byte)7).RoundUpToPowerOf2());
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RoundUpToPowerOf2_ShouldReturnSameValue_GivenPowerOf2()
|
|
{
|
|
for (var i = 0; i < 8; i++)
|
|
{
|
|
var value = (byte)System.Math.Pow(2, i);
|
|
Assert.AreEqual(value, value.RoundUpToPowerOf2());
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void RoundUpToPowerOf2_ShouldReturn0_Given0()
|
|
{
|
|
Assert.AreEqual(0, ((byte)0).RoundUpToPowerOf2());
|
|
}
|
|
}
|