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]);
                }
            }
        }
Example #3
0
        public void SimulateSingleDataBitErrorTest()
        {
            String test = "MR. UTTERSON the lawyer was a man of a rugged countenance, that was never lighted by a smile; cold, scanty and embarrassed in discourse; backward in sentiment; lean, long, dusty, dreary, and yet somehow lovable.At friendly meetings, and when the wine was to his taste, something eminently human beaconed from his eye; something indeed which never found its way into his talk, but which spoke not only in these silent symbols of the after-dinner face, but more often and loudly in the acts of his life.He was austere with himself; drank gin when he was alone, to mortify a taste for vintages; and though he enjoyed the theatre, had not crossed the doors of one for twenty years. But he had an approved tolerance for others; sometimes wondering, almost with envy, at the high pressure of spirits involved in their misdeeds; and in any extremity inclined to help rather than to reprove. ‘I incline to, Cain’s heresy,’ he used to say. ‘I let my brother go to the devil in his quaintly: ‘own way.’ In this character, it was frequently his fortune to be the last reputable acquaintance and the last good influence in the lives of down-going men.And to such as these, so long as they came about his chambers, he never marked a shade of change in his demeanour.";

            for (int i = 1; i < test.Length; i++)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(test, 0, i);

                HammingString hs = new HammingString(sb.ToString());

                // Simulate single data bit error
                hs.SimulateSingleDataBitError();

                // builds and checks report
                HammingReport hr = hs.BuildReport();
                Assert.IsTrue(hr.Status == ErrorTypesEnum.DataBitError);
                Assert.IsTrue(hr.Syndrome > 0);
                Assert.IsTrue(hr.Corrected);

                // check return value
                String retVal = hs.RetrieveValue();
                Assert.IsNotNull(retVal);
                Assert.AreEqual(sb.ToString(), retVal);
            }
        }
Example #4
0
        public void SimulateDoubleBitErrorTest()
        {
            for (int i = 0; i < 100; i++)
            {
                int            test = rand.Next(Int32.MaxValue);
                HammingInteger hi   = HammingInteger.EncodeInt(test);

                // Simulate double bit error
                hi.SimulateDoubleBitError();

                // builds and checks report
                HammingReport hr = hi.BuildReport();
                Assert.IsTrue(hr.Status == ErrorTypesEnum.MultiBitError);
                Assert.IsTrue(hr.Syndrome > 0);
                Assert.IsFalse(hr.Corrected);

                // Cannot check return value since its uncorrectable
            }
        }
Example #5
0
        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);
            }
        }
Example #6
0
        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);
            }
        }