public void EncodingTest() { // Int8 encoding test byte testByte = 10; HammingInteger hi = new HammingInteger(testByte); byte? returnByte = hi.RetrieveValue() as byte?; Assert.IsNotNull(returnByte); Assert.AreEqual(testByte, returnByte); // Int16 encoding test Int16 testInt16 = 100; hi = new HammingInteger(testInt16); Int16?returnInt16 = hi.RetrieveValue() as Int16?; Assert.IsNotNull(returnInt16); Assert.AreEqual(testInt16, returnInt16); // Int32 encoding test Int32 testInt32 = 1000; hi = new HammingInteger(testInt32); Int32?returnInt32 = hi.RetrieveValue() as Int32?; Assert.IsNotNull(returnInt32); Assert.AreEqual(testInt32, returnInt32); // Int64 encoding test Int64 testInt64 = 10000; hi = new HammingInteger(testInt64); Int64?returnInt64 = hi.RetrieveValue() as Int64?; Assert.IsNotNull(returnInt64); Assert.AreEqual(testInt64, returnInt64); // Bytes array encoding test byte[] testByteArray = { 1, 10, 100 }; hi = new HammingInteger(testByteArray); byte[] returnByteArray = hi.RetrieveValue() as byte[]; Assert.IsNotNull(returnByteArray); for (int i = 0; i < returnByteArray.Length; i++) { Assert.AreEqual(testByteArray[i], returnByteArray[i]); } }
public void SimulateNoErrorsTest() { for (int i = 0; i < 100; i++) { int test = rand.Next(Int32.MaxValue); HammingInteger hi = HammingInteger.EncodeInt(test); // Simulate no error by doing nothing // builds and checks report HammingReport hr = hi.BuildReport(); Assert.IsTrue(hr.Status == ErrorTypesEnum.NoError); Assert.IsTrue(hr.Syndrome == 0); // check return value int?retVal = hi.RetrieveValue() as int?; Assert.IsNotNull(retVal); Assert.AreEqual(test, retVal); } }
public void SimulateSingleDataBitErrorTest() { for (int i = 0; i < 100; i++) { int test = rand.Next(Int32.MaxValue); HammingInteger hi = HammingInteger.EncodeInt(test); // Simulate single data bit error hi.SimulateSingleDataBitError(); // builds and checks report HammingReport hr = hi.BuildReport(); Assert.IsTrue(hr.Status == ErrorTypesEnum.DataBitError); Assert.IsTrue(hr.Syndrome > 0); Assert.IsTrue(hr.Corrected); // check return value int?retVal = hi.RetrieveValue() as int?; Assert.IsNotNull(retVal); Assert.AreEqual(test, retVal); } }