2022-04-28 08:47:48 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using X10D.Collections;
|
|
|
|
|
|
|
|
|
|
namespace X10D.Tests.Collections;
|
|
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class BoolListTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Pack8Bit_Should_Pack_Correctly()
|
|
|
|
|
{
|
|
|
|
|
var array = new[] {true, false, true, false, true, false, true, false};
|
2022-04-28 21:58:58 +00:00
|
|
|
|
Assert.AreEqual(85, array.PackByte()); // 01010101
|
2022-04-28 08:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Pack16Bit_Should_Pack_Correctly()
|
|
|
|
|
{
|
|
|
|
|
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
2022-04-28 21:58:58 +00:00
|
|
|
|
Assert.AreEqual(2901, array.PackInt16()); // 101101010101
|
2022-04-28 08:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Pack32Bit_Should_Pack_Correctly()
|
|
|
|
|
{
|
|
|
|
|
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
2022-04-28 21:58:58 +00:00
|
|
|
|
Assert.AreEqual(2901, array.PackInt32()); // 101101010101
|
2022-04-28 08:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Pack64Bit_Should_Pack_Correctly()
|
|
|
|
|
{
|
|
|
|
|
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
2022-04-28 21:58:58 +00:00
|
|
|
|
Assert.AreEqual(2901, array.PackInt64()); // 101101010101
|
2022-04-28 08:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Pack_ShouldThrow_GivenLargeArray()
|
|
|
|
|
{
|
|
|
|
|
bool[] array = Enumerable.Repeat(false, 65).ToArray();
|
2022-04-28 21:58:58 +00:00
|
|
|
|
Assert.ThrowsException<ArgumentException>(() => array.PackByte());
|
|
|
|
|
Assert.ThrowsException<ArgumentException>(() => array.PackInt16());
|
|
|
|
|
Assert.ThrowsException<ArgumentException>(() => array.PackInt32());
|
|
|
|
|
Assert.ThrowsException<ArgumentException>(() => array.PackInt64());
|
2022-04-28 08:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void Pack_ShouldThrow_GivenNull()
|
|
|
|
|
{
|
|
|
|
|
bool[]? array = null;
|
2022-04-28 21:58:58 +00:00
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackByte());
|
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt16());
|
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt32());
|
|
|
|
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt64());
|
2022-04-28 08:47:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|