mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:48:46 +00:00
Update byte unit tests to reflect new API
This commit is contained in:
parent
7192b46e9f
commit
132573e262
@ -1,101 +1,81 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace X10D.Tests.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions" />.
|
||||
/// Tests for <see cref="ByteExtensions" />
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class ByteTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions.AsString" />.
|
||||
/// Tests <see cref="ByteExtensions.GetBytes" />.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void AsString()
|
||||
public void GetBytes()
|
||||
{
|
||||
byte[] a = { 0x00, 0x73, 0xc6, 0xff };
|
||||
Assert.AreEqual("00-73-C6-FF", a.AsString());
|
||||
const byte byteMinValue = byte.MinValue;
|
||||
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>
|
||||
/// Tests for <see cref="ByteExtensions.GetInt16" />.
|
||||
/// Tests <see cref="ByteExtensions.IsEven" />.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GetInt16()
|
||||
public void IsEven()
|
||||
{
|
||||
byte[] a = { 0xF3, 0x3F };
|
||||
Assert.AreEqual(16371, a.GetInt16());
|
||||
const byte one = 1;
|
||||
const byte two = 2;
|
||||
|
||||
var oneEven = one.IsEven();
|
||||
var twoEven = two.IsEven();
|
||||
|
||||
Assert.IsFalse(oneEven);
|
||||
Assert.IsTrue(twoEven);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions.GetInt32" />.
|
||||
/// Tests <see cref="ByteExtensions.IsOdd" />.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GetInt32()
|
||||
public void IsOdd()
|
||||
{
|
||||
byte[] a = { 0xB0, 0x0B, 0x13, 0x5F };
|
||||
Assert.AreEqual(1595083696, a.GetInt32());
|
||||
const byte one = 1;
|
||||
const byte two = 2;
|
||||
|
||||
var oneOdd = one.IsOdd();
|
||||
var twoOdd = two.IsOdd();
|
||||
|
||||
Assert.IsTrue(oneOdd);
|
||||
Assert.IsFalse(twoOdd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions.GetInt64" />.
|
||||
/// Tests <see cref="ByteExtensions.ToBoolean" />.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GetInt64()
|
||||
public void ToBoolean()
|
||||
{
|
||||
byte[] a = { 0xB0, 0x0B, 0x13, 0x50, 0x05, 0x31, 0xB0, 0x0B };
|
||||
Assert.AreEqual(842227029206305712L, a.GetInt64());
|
||||
}
|
||||
const byte zero = 0;
|
||||
const byte one = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions.GetString(IEnumerable{byte})" />.
|
||||
/// </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());
|
||||
}
|
||||
const bool trueValue = true;
|
||||
const bool falseValue = false;
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions.GetString(IEnumerable{byte}, Encoding)" />.
|
||||
/// </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));
|
||||
}
|
||||
var zeroBoolean = zero.ToBoolean();
|
||||
var oneBoolean = one.ToBoolean();
|
||||
|
||||
/// <summary>
|
||||
/// Tests for <see cref="ByteExtensions.GetUInt16" />.
|
||||
/// </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());
|
||||
Assert.AreEqual(falseValue, zeroBoolean);
|
||||
Assert.AreEqual(trueValue, oneBoolean);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user