123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System;
- using System.Linq;
- using System.Text;
- namespace VeederRoot_Test
- {
- [TestClass]
- public class Util
- {
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod1()
- {
- var raw = "43BA8C60";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(1136299104, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod2()
- {
- var raw = "4 1 C 4 1 2 F C";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(1103368956, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod3()
- {
- var raw = "43BA8CCD";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(1136299213, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod4()
- {
- var raw = "43ba8ccd";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(1136299213, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod5()
- {
- var raw = "01";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(1, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod6()
- {
- var raw = "11";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(17, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod7()
- {
- var raw = "A1";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(161, c);
- }
- [TestMethod]
- public void ConvertHexStrToLong_TestMethod8()
- {
- var raw = "1101";
- var c = VeederRoot_ATG_Console.Util.ConvertHexStrToLong(raw);
- Assert.AreEqual(4353, c);
- }
- [TestMethod]
- public void ConvertHexBcdStrToBytes_TestMethod1()
- {
- var raw = new byte[] { 0x34, 0x33, 0x42, 0x41, 0x38, 0x43, 0x43, 0x44 };
- var actual = VeederRoot_ATG_Console.Util.ConvertHexBcdStrToBytes(raw);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(new byte[] { 0x43, 0xBA, 0x8C, 0xCD }, actual));
- }
- [TestMethod]
- public void ConvertHexBcdStrToBytes_TestMethod2()
- {
- var raw = new byte[] { 0x31, 0x33, };
- var actual = VeederRoot_ATG_Console.Util.ConvertHexBcdStrToBytes(raw);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(new byte[] { 0x13 }, actual));
- }
- [TestMethod]
- public void ConvertHexBcdStrToBytes_TestMethod3()
- {
- var raw = new byte[] { 0x30, 0x33, };
- var actual = VeederRoot_ATG_Console.Util.ConvertHexBcdStrToBytes(raw);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(new byte[] { 0x03 }, actual));
- }
- #region ConvertIEEEWith4BytesToDouble
- [TestMethod]
- public void ConvertIEEEWith4BytesToDouble_TestMethod1()
- {
- byte[] raw = new byte[] { 0x3F, 0x80, 0x00, 0x00 };
- var c = VeederRoot_ATG_Console.Util.ConvertIEEEWith4BytesToDouble(raw);
- Assert.AreEqual(1, c);
- }
- [TestMethod]
- public void ConvertIEEEWith4BytesToDouble_TestMethod2()
- {
- byte[] raw = new byte[] { 0xB8, 0xD1, 0xB7, 0x17 };
- var c = VeederRoot_ATG_Console.Util.ConvertIEEEWith4BytesToDouble(raw, 4);
- Assert.AreEqual(-0.0001, c);
- }
- [TestMethod]
- public void ConvertIEEEWith4BytesToDouble_TestMethod3()
- {
- byte[] raw = new byte[] { 0xC2, 0xC7, 0xFA, 0xE1 };
- var c = VeederRoot_ATG_Console.Util.ConvertIEEEWith4BytesToDouble(raw, 2);
- //var f = Math.Round(c, 2);
- Assert.AreEqual(-99.99, c);
- }
- [TestMethod]
- public void ConvertIEEEWith4BytesToDouble_TestMethod4()
- {
- byte[] raw = new byte[] { 0x46, 0x1C, 0x40, 0x00 };
- var c = VeederRoot_ATG_Console.Util.ConvertIEEEWith4BytesToDouble(raw);
- Assert.AreEqual(10000, c);
- }
- [TestMethod]
- public void ConvertIEEEWith4BytesToDouble_TestMethod5()
- {
- byte[] raw = new byte[] { 0x43, 0xBA, 0x8C, 0xCD };
- var c = VeederRoot_ATG_Console.Util.ConvertIEEEWith4BytesToDouble(raw);
- Assert.AreEqual(373.1, Math.Round(c, 1));
- }
- #endregion
- #region ConvertDoubleToIEEE4Bytes
- [TestMethod]
- public void ConvertDoubleToIEEE4Bytes_TestMethod1()
- {
- byte[] expect = new byte[] { 0x3F, 0x80, 0x00, 0x00 };
- var actual = VeederRoot_ATG_Console.Util.ConvertDoubleToIEEE4Bytes(1);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(expect, actual));
- }
- [TestMethod]
- public void ConvertDoubleToIEEE4Bytes_TestMethod2()
- {
- byte[] expect = new byte[] { 0xB8, 0xD1, 0xB7, 0x17 };
- var actual = VeederRoot_ATG_Console.Util.ConvertDoubleToIEEE4Bytes(-0.0001);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(expect, actual));
- }
- [TestMethod]
- public void ConvertDoubleToIEEE4Bytes_TestMethod3()
- {
- byte[] expect = new byte[] { 0xC2, 0xC7, 0xFA, 0xE1 };
- var actual = VeederRoot_ATG_Console.Util.ConvertDoubleToIEEE4Bytes(-99.99);
- //var f = Math.Round(c, 2);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(expect, actual));
- }
- [TestMethod]
- public void ConvertDoubleToIEEE4Bytes_TestMethod4()
- {
- byte[] expect = new byte[] { 0x46, 0x1C, 0x40, 0x00 };
- var actual = VeederRoot_ATG_Console.Util.ConvertDoubleToIEEE4Bytes(10000);
- Assert.AreEqual(true, Outgoing_Message.ValueEquals(expect, actual));
- }
- #endregion
- }
- }
|