ErrorsManager/Python/tests.py

65 lines
1.7 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from ErrorsManager import ErrorsManager
from json import dumps as json_encode
errors_manager:ErrorsManager = ErrorsManager()
print(errors_manager.to_string(105))
print(errors_manager.to_array(105))
print(errors_manager.to_array_binary(105))
print(errors_manager.process(105, ["error_message_" + str(i) for i, _ in enumerate("0123456789abcdef")]))
print(errors_manager.bits(105))
print(errors_manager.bits("pB"))
print(errors_manager.bits([41, 1]))
options = [-10, -5, -3, -1, 0, 1, 3, 5, 10]
filler = ""
results = []
while len(filler) < 30:
filler += " "
def format(value, characters):
return " " + (
json_encode(value).replace(",", ", ") + filler
)[:characters]
for i, value in enumerate([105, "pB", [41, 1]]):
for bits in options:
new_value = errors_manager.bitwise(value, bits)
example = [
format(value, 7),
format(errors_manager.to_array_binary(value), 20),
format(bits, 4),
format(new_value, 12),
format(errors_manager.to_array_binary(new_value), 30)
]
results += [example]
print(example)
print("")
# [105, "pB", [41, 1]].forEach((value, i) => options.forEach(bits => {
# const new_value = errors_manager.bitwise(value, bits)
# results.push([
# format(value, 7),
# format(errors_manager.to_array_binary(value), 20),
# format(bits, 4),
# format(new_value, 12),
# format(errors_manager.to_array_binary(new_value), 30)
# ])
# // print(results[results.length - 1])
# }))
# -- print(results)
# // print(results.map(result => result.join("|")).join("\n"))