import unittest

from h8536.emulator.report_queue_probe import (
    build_expected_report_frame,
    encode_report_header,
    report_payload_selector,
)


class EmulatorReportQueueProbeTest(unittest.TestCase):
    def test_report_word_0204_builds_observed_gated_active_frame(self):
        self.assertEqual(encode_report_header(0x0204), (0x01, 0x00, 0x04))
        self.assertEqual(report_payload_selector(0x0204), 0x0004)
        self.assertEqual(build_expected_report_frame(0x0204, 0x0000), bytes.fromhex("01 00 04 00 00 5F"))

    def test_report_word_0404_builds_observed_transition_frame(self):
        self.assertEqual(encode_report_header(0x0404), (0x02, 0x00, 0x04))
        self.assertEqual(report_payload_selector(0x0404), 0x0004)
        self.assertEqual(build_expected_report_frame(0x0404, 0x0000), bytes.fromhex("02 00 04 00 00 5C"))

    def test_payload_bytes_feed_frame_value_and_checksum(self):
        self.assertEqual(build_expected_report_frame(0x0204, 0x1234), bytes.fromhex("01 00 04 12 34 79"))


if __name__ == "__main__":
    unittest.main()
