diff --git a/X10D.Tests/src/Core/ByteTests.cs b/X10D.Tests/src/Core/ByteTests.cs index d33625d..28cfc04 100644 --- a/X10D.Tests/src/Core/ByteTests.cs +++ b/X10D.Tests/src/Core/ByteTests.cs @@ -1,101 +1,81 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace X10D.Tests.Core { /// - /// Tests for . + /// Tests for /// [TestClass] public class ByteTests { /// - /// Tests for . + /// Tests . /// [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); } /// - /// Tests for . + /// Tests . /// [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); } /// - /// Tests for . + /// Tests . /// [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); } /// - /// Tests for . + /// Tests . /// [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; - /// - /// Tests for . - /// - [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; - /// - /// Tests for . - /// - [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(); - /// - /// Tests for . - /// - [TestMethod] - public void GetUInt16() - { - byte[] a = { 0xF3, 0x3F }; - Assert.AreEqual(16371, a.GetUInt16()); - } - - /// - /// Tests for . - /// - [TestMethod] - public void GetUInt32() - { - byte[] a = { 0xB0, 0x0B, 0x13, 0x5F }; - Assert.AreEqual(1595083696U, a.GetUInt32()); - } - - /// - /// Tests for . - /// - [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); } } }