Split experiments from tests
The tests/ directory held 50 laboratory programs and no tests. They model channels, run hundreds of repetitions and write CSV, PNG and reports; calling that a test suite blocked introducing a real one, because any pytest run would have collected the labs and re-executed every experiment. - move all 50 lab programs to experiments/ with git mv, preserving history - rewrite the 38 cross-imports between labs from tests.labNNN to experiments.labNNN - leave tests/ empty for actual fast checks of protocol/ - point quick_gate and the hook at the new layout and add experiments/ to the syntax sweep - update the paths quoted in the Lab042 specification and the verifier agent definition This also defuses the import-time work finding without touching 41 files: the labs still create directories and write files on import, but nothing imports them now except the gate, which does so deliberately. Gate passes: syntax clean, protocol imports, 15 lab modules import, 2 functional suites run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
61
experiments/lab001_utf8_russian.py
Normal file
61
experiments/lab001_utf8_russian.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
Lab001, часть 2.
|
||||
Русский текст, символы, байты и кодировка UTF-8.
|
||||
|
||||
Цель:
|
||||
1. Увидеть разницу между количеством символов и количеством байтов.
|
||||
2. Посмотреть, сколько байтов занимает каждая русская буква.
|
||||
3. Восстановить исходный текст из байтов.
|
||||
"""
|
||||
|
||||
# Исходное сообщение
|
||||
message = "ПРИВЕТ SDR"
|
||||
|
||||
# Преобразование текста в байты UTF-8
|
||||
encoded_message = message.encode("utf-8")
|
||||
|
||||
# Обратное преобразование байтов в текст
|
||||
decoded_message = encoded_message.decode("utf-8")
|
||||
|
||||
|
||||
print("Исходный текст:")
|
||||
print(message)
|
||||
|
||||
print("\nКоличество символов:")
|
||||
print(len(message))
|
||||
|
||||
print("\nКоличество байтов UTF-8:")
|
||||
print(len(encoded_message))
|
||||
|
||||
print("\nОбъект bytes:")
|
||||
print(encoded_message)
|
||||
|
||||
print("\nВсе байты в десятичном виде:")
|
||||
print(list(encoded_message))
|
||||
|
||||
print("\nПодробно по каждому символу:")
|
||||
|
||||
for character in message:
|
||||
character_bytes = character.encode("utf-8")
|
||||
|
||||
decimal_bytes = list(character_bytes)
|
||||
|
||||
binary_bytes = " ".join(
|
||||
f"{byte:08b}" for byte in character_bytes
|
||||
)
|
||||
|
||||
print(
|
||||
f"{character!r:>4} "
|
||||
f"→ байтов: {len(character_bytes)} "
|
||||
f"→ числа: {decimal_bytes} "
|
||||
f"→ биты: {binary_bytes}"
|
||||
)
|
||||
|
||||
print("\nВосстановленный текст:")
|
||||
print(decoded_message)
|
||||
|
||||
# Автоматические проверки
|
||||
assert decoded_message == message
|
||||
assert len(encoded_message) >= len(message)
|
||||
|
||||
print("\nПроверка пройдена: русский текст восстановлен без ошибок.")
|
||||
Reference in New Issue
Block a user