예제 #1
0
 def test_correction_one_error_in_control_sum(self):
     code = np.array([1, 1, 0, 0, 1, 1, 0, 0])
     code[7] += 1
     code %= 2
     expected = (np.array([1, 1, 0, 0, 1, 1, 0, 0]), 1)
     actual = Hamming.correction(code)
     np.testing.assert_array_equal(expected[0], actual[0])
     self.assertEqual(expected[1], actual[1])
예제 #2
0
 def test_correction_random_one_error(self):
     code = np.array([1, 1, 0, 0, 1, 1, 0, 0])
     error = sample(range(0, 7), 1)
     code[error[0]] += 1
     code %= 2
     expected = (np.array([1, 1, 0, 0, 1, 1, 0, 0]), 1)
     actual = Hamming.correction(code)
     np.testing.assert_array_equal(expected[0], actual[0])
     self.assertEqual(expected[1], actual[1])
예제 #3
0
 def test_correction_zero_errors(self):
     code = np.array([1, 1, 0, 0, 1, 1, 0, 0])
     expected = (np.array([1, 1, 0, 0, 1, 1, 0, 0]), 0)
     actual = Hamming.correction(code)
     np.testing.assert_array_equal(expected[0], actual[0])
     self.assertEqual(expected[1], actual[1])