import subprocess
import sys


def test_condefects_0():
    proc = subprocess.run(
        [sys.executable, "buggy.py"],
        input='3\na -5\nab 10\nba -20\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = 'Infinity\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='28\na -5\nab 10\nba -20\nbb -20\nbc -20\nbd -20\nbe -20\nbf -20\nbg -20\nbh -20\nbi -20\nbj -20\nbk -20\nbl -20\nbm -20\nbn -20\nbo -20\nbp -20\nbq -20\nbr -20\nbs -20\nbt -20\nbu -20\nbv -20\nbw -20\nbx -20\nby -20\nbz -20\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '5\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='26\na -1\nb -1\nc -1\nd -1\ne -1\nf -1\ng -1\nh -1\ni -1\nj -1\nk -1\nl -1\nm -1\nn -1\no -1\np -1\nq -1\nr -1\ns -1\nt -1\nu -1\nv -1\nw -1\nx -1\ny -1\nz -1\n',
        capture_output=True,
        text=True,
        timeout=10,
    )
    expected = '-1\n'
    actual = proc.stdout.strip()
    assert actual == expected.strip(), (
        f"Expected {expected.strip()!r}, got {actual!r}"
    )
