12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<byte> array1, IEnumerable<byte> 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: <SOH>B000000012FE0A<EOT>
- 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: <SOH>B100000501FE06<EOT>
- 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);
- }
- }
- }
|