using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace VeederRoot_Test { [TestClass] public class Parser { public static bool ValueEquals(IEnumerable array1, IEnumerable array2) { if (array1 == null && array2 == null) { return true; } if ((array1 == null) || (array2 == null)) { return false; } if (array1.Count() != array2.Count()) { return false; } if (array1.Equals(array2)) { return true; } else { for (int Index = 0; Index < array1.Count(); Index++) { if (!Equals(array1.ElementAt(Index), array2.ElementAt(Index))) { return false; } } } return true; } [TestMethod] public void CaculateCheckSum_TestMethod1() { VeederRoot_ATG_Console.Parser parser = new VeederRoot_ATG_Console.Parser(); //Example Report 1: B000000012FE0A var expect = 0x0F * Math.Pow(16, 3) + 0x0E * Math.Pow(16, 2) + 0x00 * 16 + 0x0A; var raw = new byte[] { 0x01 }.Concat(Encoding.ASCII.GetBytes("B000000012")); var actual = parser.CaculateCheckSum(raw.ToArray()); Assert.AreEqual(true, actual == expect); } [TestMethod] public void CaculateCheckSum_TestMethod2() { VeederRoot_ATG_Console.Parser parser = new VeederRoot_ATG_Console.Parser(); //Example Report 2: B100000501FE06 var expect = 0x0F * Math.Pow(16, 3) + 0x0E * Math.Pow(16, 2) + 0x00 * 16 + 0x06; var raw = new byte[] { 0x01 }.Concat(Encoding.ASCII.GetBytes("B100000501")); var actual = parser.CaculateCheckSum(raw.ToArray()); Assert.AreEqual(true, actual == expect); } } }