public void GetParityTest1() { byte[] data = new byte[] { 1, 2, 3, 4, 5, 3, 5, 7, 8 }; int start = 0; int length = 9; byte expected = 8; byte actual; actual = XORParity.GetParity(data, start, length); Assert.AreEqual(expected, actual); //验证 length 异常 try { start = 1; actual = XORParity.GetParity(data, start, length); Assert.AreEqual(expected, actual); } catch (Exception) { Assert.IsFalse(false); } //验证 Null异常 try { data = null; actual = XORParity.GetParity(data, start, length); Assert.AreEqual(expected, actual); } catch (Exception) { Assert.IsFalse(false); } }
public void GetParityTest2() { byte[] data = new byte[] { 1, 2, 3, 4, 5, 3, 5, 7, 8 }; byte expected = 8; byte actual; actual = XORParity.GetParity(data); Assert.AreEqual(expected, actual); //验证异常 try { data = null; actual = XORParity.GetParity(data); Assert.AreEqual(expected, actual); } catch (Exception) { Assert.IsFalse(false); } }