import subprocess
import sys


def test_condefects_0():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='1\nb\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'b\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_1():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='4101\[encoded data, 4102 characters]\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '[encoded data, 4101 characters]\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_2():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='629\nfgihnqkaqcbmapwrmamdpgrfbqflsxtwphgvfbynaoydxxrdtqdcyvguzuwwgtnnmwqlzywilqfdrsjpjmtulwpcxapdukhnmcpnghngidpgwgrkleuppprtqwmxawzhsazryttseqznpjbcvxkoswlwdhounflidksjvixezsyswlyvsktjslmnkllgzxhqbkavdyacazajhmrdjmtwiovvihoawisdfniuhhpjwwcjpyfwbujqmjfbugmsdcolwnqsrmpwtbadkbdsozrdudonbnzrmlomsyjnlqnmitczshqljolcxnpnandfwbuqwowqsaslpivhegxfdsdzxiredvfyfdysbiqakrofdljuctcucaxksvmdkmlxnzczqkelrvobjcvekuotgbyfzspiqufelazvymwtccfbstarqsemqgoeajisouteomtozhnkuyggrlcantsqmxlqhsfhjmrqbavklypdkaivyrhaqixwktpwpdfishbihgyzbuszgjrywekjcdjigskfuhvyrvhszfvvqslghtychlllbhkcshohqshdxvyisksxvhscpxavqxgljzxxnkwlpjzlghcfstyvdecsnxygobbfqvtmzkicd\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'aaaaaaaaaaaaaaaaaaaaaaaaabffghpwtxsvlqynboydxxrdtqdcyvguzuwwgtnnmwqlzywilqfdrsjpjmtulwpcxfpdukhnmcpnghngidpgwgrkleuppprtqwmxrwzhsgzryttseqznpjbcvxkoswlwdhounflidksjvixezsyswlyvsktjslmnkllgzxhqbkpvdydcmzmjhmrdjmtwiovvihorwisdfniuhhpjwwcjpyfwbujqmjfbugmsdcolwnqsrmpwtbwdkbdsozrdudonbnzrmlomsyjnlqnmitczshqljolcxnpnpndfwbuqwowqsmslpivhegxfdsdzxiredvfyfdysbiqbkrofdljuctcuccxksvmdkmlxnzczqkelrvobjcvekuotgbyfzspiqufelqzvymwtccfbstkrqsemqgoeqjisouteomtozhnkuyggrlcnntsqmxlqhsfhjmrqbhvklypdkiivyrhgqixwktpwpdfishbihgyzbuszgjrywekjcdjigskfuhvyrvhszfvvqslghtychlllbhkcshohqshdxvyisksxvhscpxfvqxgljzxxnkwlpjzlghcfstyvdecsnxygobbfqvtmzkicd\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_3():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='8255\[encoded data, 8256 characters]\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '[encoded data, 8255 characters]\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )


def test_condefects_4():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='4\ndcab\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'acdb\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )
