public void SimulateSingleDataBitErrorTest()
        {
            for (int byteSize = 1; byteSize < 16; byteSize++)
            {
                byte[] byteArray = createByteArray(byteSize);

                HammingBase hc = HammingBase.EncodeByteArray(byteArray);  // encodes byte array

                // Simulate Master Bit Error
                hc.SimulateSingleDataBitError();

                // builds and checks report
                HammingReport hr = hc.BuildReport();
                Assert.IsTrue(hr.Status == ErrorTypesEnum.DataBitError);
                Assert.IsTrue(hr.Syndrome > 0);
                Assert.IsTrue(hr.Corrected); // Ensures HammingObject is corrected

                // checks return value
                byte[] retrievedValue = hc.RetrieveValue() as byte[];
                Assert.IsNotNull(retrievedValue);
                Assert.IsTrue(retrievedValue.Length == byteArray.Length);
                for (int i = 0; i < byteArray.Length; i++)
                {
                    Assert.IsTrue(byteArray[i] == retrievedValue[i]);
                }
            }
        }
        public void SimulateNoErrorTest()
        {
            for (int byteSize = 1; byteSize < 16; byteSize++)
            {
                byte[] byteArray = createByteArray(byteSize);

                HammingBase hc = HammingBase.EncodeByteArray(byteArray); // encodes byte array

                // Simulate no error by doing nothing

                // builds and checks report
                HammingReport hr = hc.BuildReport();
                Assert.IsTrue(hr.Status == ErrorTypesEnum.NoError);
                Assert.IsTrue(hr.Syndrome == 0);

                // checks return value
                byte[] retrievedValue = hc.RetrieveValue() as byte[];
                Assert.IsNotNull(retrievedValue);
                Assert.IsTrue(retrievedValue.Length == byteArray.Length);
                for (int i = 0; i < byteArray.Length; i++)
                {
                    Assert.IsTrue(byteArray[i] == retrievedValue[i]);
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            byte[]      bytesArray = { 0x90, 0x01, 0x0a, 0x20 };
            HammingBase code       = new HammingBase(bytesArray);

            code.BuildReport();

            byte[] data = code.RetrieveValue() as byte[];
            Console.WriteLine("Success!");
        }