Update byte unit tests to reflect new API

This commit is contained in:
Oliver Booth 2021-07-20 00:53:43 +01:00
parent 7192b46e9f
commit 132573e262
No known key found for this signature in database
GPG Key ID: A4AC17007530E9B4
1 changed files with 45 additions and 65 deletions

View File

@ -1,101 +1,81 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace X10D.Tests.Core namespace X10D.Tests.Core
{ {
/// <summary> /// <summary>
/// Tests for <see cref="ByteExtensions" />. /// Tests for <see cref="ByteExtensions" />
/// </summary> /// </summary>
[TestClass] [TestClass]
public class ByteTests public class ByteTests
{ {
/// <summary> /// <summary>
/// Tests for <see cref="ByteExtensions.AsString" />. /// Tests <see cref="ByteExtensions.GetBytes" />.
/// </summary> /// </summary>
[TestMethod] [TestMethod]
public void AsString() public void GetBytes()
{ {
byte[] a = { 0x00, 0x73, 0xc6, 0xff }; const byte byteMinValue = byte.MinValue;
Assert.AreEqual("00-73-C6-FF", a.AsString()); const byte byteMaxValue = byte.MaxValue;
var minValueBytes = new[] { byteMinValue };
var maxValueBytes = new[] { byteMaxValue };
var minValueResult = byteMinValue.GetBytes();
var maxValueResult = byteMaxValue.GetBytes();
CollectionAssert.AreEqual(minValueBytes, minValueResult);
CollectionAssert.AreEqual(maxValueBytes, maxValueResult);
} }
/// <summary> /// <summary>
/// Tests for <see cref="ByteExtensions.GetInt16" />. /// Tests <see cref="ByteExtensions.IsEven" />.
/// </summary> /// </summary>
[TestMethod] [TestMethod]
public void GetInt16() public void IsEven()
{ {
byte[] a = { 0xF3, 0x3F }; const byte one = 1;
Assert.AreEqual(16371, a.GetInt16()); const byte two = 2;
var oneEven = one.IsEven();
var twoEven = two.IsEven();
Assert.IsFalse(oneEven);
Assert.IsTrue(twoEven);
} }
/// <summary> /// <summary>
/// Tests for <see cref="ByteExtensions.GetInt32" />. /// Tests <see cref="ByteExtensions.IsOdd" />.
/// </summary> /// </summary>
[TestMethod] [TestMethod]
public void GetInt32() public void IsOdd()
{ {
byte[] a = { 0xB0, 0x0B, 0x13, 0x5F }; const byte one = 1;
Assert.AreEqual(1595083696, a.GetInt32()); const byte two = 2;
var oneOdd = one.IsOdd();
var twoOdd = two.IsOdd();
Assert.IsTrue(oneOdd);
Assert.IsFalse(twoOdd);
} }
/// <summary> /// <summary>
/// Tests for <see cref="ByteExtensions.GetInt64" />. /// Tests <see cref="ByteExtensions.ToBoolean" />.
/// </summary> /// </summary>
[TestMethod] [TestMethod]
public void GetInt64() public void ToBoolean()
{ {
byte[] a = { 0xB0, 0x0B, 0x13, 0x50, 0x05, 0x31, 0xB0, 0x0B }; const byte zero = 0;
Assert.AreEqual(842227029206305712L, a.GetInt64()); const byte one = 1;
}
/// <summary> const bool trueValue = true;
/// Tests for <see cref="ByteExtensions.GetString(IEnumerable{byte})" />. const bool falseValue = false;
/// </summary>
[TestMethod]
public void GetString()
{
byte[] a = { 0x48, 0xc3, 0xa9, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64 };
Assert.AreEqual("H\u00e9llo World", a.GetString());
}
/// <summary> var zeroBoolean = zero.ToBoolean();
/// Tests for <see cref="ByteExtensions.GetString(IEnumerable{byte}, Encoding)" />. var oneBoolean = one.ToBoolean();
/// </summary>
[TestMethod]
public void GetStringAscii()
{
byte[] a = { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64 };
Assert.AreEqual("Hello World", a.GetString(Encoding.ASCII));
}
/// <summary> Assert.AreEqual(falseValue, zeroBoolean);
/// Tests for <see cref="ByteExtensions.GetUInt16" />. Assert.AreEqual(trueValue, oneBoolean);
/// </summary>
[TestMethod]
public void GetUInt16()
{
byte[] a = { 0xF3, 0x3F };
Assert.AreEqual(16371, a.GetUInt16());
}
/// <summary>
/// Tests for <see cref="ByteExtensions.GetUInt32" />.
/// </summary>
[TestMethod]
public void GetUInt32()
{
byte[] a = { 0xB0, 0x0B, 0x13, 0x5F };
Assert.AreEqual(1595083696U, a.GetUInt32());
}
/// <summary>
/// Tests for <see cref="ByteExtensions.GetUInt64" />.
/// </summary>
[TestMethod]
public void GetUInt64()
{
byte[] a = { 0xB0, 0x0B, 0x13, 0x50, 0x05, 0x31, 0xB0, 0x0B };
Assert.AreEqual(842227029206305712UL, a.GetUInt64());
} }
} }
} }