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:
LittleSam129
2026-08-10 14:34:58 +03:00
parent c9569164e0
commit c486039053
55 changed files with 63 additions and 62 deletions

View File

@@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 10 17:19:11 2026
@author: user
"""
"""
Lab004. Проверка модуля protocol.packet.
Проверяем:
1. Формирование пакета.
2. Разбор исправного пакета.
3. Восстановление текста.
4. Обнаружение повреждения CRC.
"""
from protocol.packet import (
CRCError,
HEADER_SIZE,
MESSAGE_TYPE_TEXT,
build_packet,
parse_packet,
)
# ============================================================
# Формирование пакета
# ============================================================
message = "ПРИВЕТ SDR"
payload = message.encode("utf-8")
sequence_number = 7
packet = build_packet(
payload=payload,
message_type=MESSAGE_TYPE_TEXT,
sequence_number=sequence_number,
)
print("Исходное сообщение:")
print(message)
print("\nСформированный пакет:")
print(packet.hex(" "))
print("\nРазмер пакета:")
print(len(packet), "байт")
# ============================================================
# Разбор исправного пакета
# ============================================================
parsed_packet = parse_packet(packet)
restored_message = parsed_packet.payload.decode("utf-8")
print("\n--- Разобранный пакет ---")
print("Версия:")
print(parsed_packet.version)
print("\nТип сообщения:")
print(parsed_packet.message_type)
print("\nПорядковый номер:")
print(parsed_packet.sequence_number)
print("\nПолезная нагрузка:")
print(parsed_packet.payload)
print("\nВосстановленное сообщение:")
print(restored_message)
assert parsed_packet.message_type == MESSAGE_TYPE_TEXT
assert parsed_packet.sequence_number == sequence_number
assert restored_message == message
print("\nИсправный пакет успешно разобран.")
# ============================================================
# Повреждение одного бита
# ============================================================
corrupted_packet = bytearray(packet)
# В строке "ПРИВЕТ SDR" буква S находится
# по индексу 13 внутри полезной нагрузки.
payload_byte_index = 13
packet_byte_index = (
HEADER_SIZE + payload_byte_index
)
corrupted_packet[packet_byte_index] ^= 0x01
print("\n--- Проверка повреждённого пакета ---")
try:
parse_packet(corrupted_packet)
except CRCError as error:
print("Повреждение обнаружено.")
print(error)
else:
raise AssertionError(
"Ошибка: повреждённый пакет был принят как исправный"
)
print("\nВсе проверки Lab004 успешно выполнены.")