def get_tasks(): if request.method == 'OPTIONS': response = Response('', status=200, mimetype='application/json') response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') return response else: if request.headers['Content-Type'] == 'application/json': json = request.json print(json) binary = Converter.utf8_to_binary(json['phrase']) code = Hamming(binary, json['resend']) result = code.get_all() result = { 'result': Converter.binary_to_utf8(result), 'binary': binary, 'statistic': code.get_statistic() } response = jsonify(result) response.headers.add('Access-Control-Allow-Origin', '*') return response else: return unsupported_media_type()
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])
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])
def test_recover3(self): expected = np.array([1, 1, 1, 1]) actual = Hamming.recover(np.array([1, 1, 1, 1, 1, 1, 1, 1])) np.testing.assert_array_equal(expected, actual)
def test_decryption1(self): expected = np.array([0, 1, 1, 0, 0, 1, 1, 0]) actual = Hamming.decryption(np.array([1, 1, 0, 1])) np.testing.assert_array_equal(expected, actual)
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])