コード例 #1
0
def move_up2():
    """3x3 board: move blank up twice."""
    result = uva.check50.py.run("fifteen.py",
                                argv=["fifteen.py", "3"],
                                stdin=["3", "6", "-1"])

    expected = re.compile(
        "(08 07 06)[ ]*(\n)"
        "(05 04 __)[ ]*(\n)"
        "(02 01 03)[ ]*(\n)", re.MULTILINE)

    match = expected.search(result.stdout)

    if not match:
        raise check50.Mismatch("08 07 06\n05 04 __\n02 01 03\n", result.stdout)

    stdout = result.stdout[match.end():]

    expected = re.compile(
        "(08 07 __)[ ]*(\n)"
        "(05 04 06)[ ]*(\n)"
        "(02 01 03)[ ]*(\n)", re.MULTILINE)

    if not expected.search(stdout):
        raise check50.Mismatch("08 07 __\n05 04 06\n02 01 03\n", stdout)
コード例 #2
0
def solve3():
    """solves a 3x3 board."""
    steps = [
        "3", "4", "1", "2", "5", "8", "7", "6", "4", "1", "2", "5", "8", "7",
        "6", "4", "1", "2", "4", "1", "2", "3", "5", "4", "7", "6", "1", "2",
        "3", "7", "4", "8", "6", "4", "8", "5", "7", "8", "5", "6", "4", "5",
        "6", "7", "8", "6", "5", "4", "7", "8"
    ]

    result = uva.check50.py.run("fifteen.py",
                                argv=["fifteen.py", "3"],
                                stdin=steps)

    expected = re.compile(
        "(01 02 03)[ ]*(\n)"
        "(04 05 06)[ ]*(\n)"
        "(07 __ 08)[ ]*(\n)", re.MULTILINE)

    match = expected.search(result.stdout)

    if not match:
        raise check50.Mismatch("01 02 03\n04 05 06\n07 __ 08\n", result.stdout)

    stdout = result.stdout[match.end():]

    expected = re.compile(
        "(01 02 03)[ ]*(\n)"
        "(04 05 06)[ ]*(\n)"
        "(07 08 __)[ ]*(\n)", re.MULTILINE)

    if not expected.search(stdout):
        raise check50.Mismatch("01 02 03\n04 05 06\n07 08 __\n", stdout)
コード例 #3
0
def move_left_right():
    """3x3 board: move blank left then right."""
    result = uva.check50.py.run("fifteen.py",
                                argv=["fifteen.py", "3"],
                                stdin=["1", "1", "-1"])

    expected = re.compile(
        "(08 07 06)[ ]*(\n)"
        "(05 04 03)[ ]*(\n)"
        "(02 __ 01)[ ]*(\n)", re.MULTILINE)

    match = expected.search(result.stdout)

    if not match:
        raise check50.Mismatch("08 07 06\n05 04 03\n02 __ 01\n", result.stdout)

    stdout = result.stdout[match.end():]

    expected = re.compile(
        "(08 07 06)[ ]*(\n)"
        "(05 04 03)[ ]*(\n)"
        "(02 01 __)[ ]*(\n)", re.MULTILINE)

    if not expected.search(stdout):
        raise check50.Mismatch("08 07 06\n05 04 03\n02 01 __\n", stdout)
コード例 #4
0
def test_functions_exist():
    """Checks that there are functions in the program """
    output = check50.run("cat credit.py").stdout()
    DefFinder = re.compile(r'\ndef \w*:|\ndef \w*\(\):|\ndef \w*\(\V*\):')
    defCount = len(DefFinder.findall(output)) > 0
    if defCount == 0:
        help = "Your code needs to have at least one function defined"
        raise check50.Mismatch("2 or more", "0", help=help)
    if defcount == 1:
        help = "Your code needs to have at least two functions defined"
        raise check50.Mismatch("2 or more", "1", help=help)
コード例 #5
0
ファイル: __init__.py プロジェクト: hirschhorn/quiz
def enqueues_and_prints_one_order_number():
    """enqueues and prints order number 1"""
    from re import match
    expected = "--> Printing all order numbers from oldest to newest.\nOrder #1\n"
    actual = check50.run("./queue").stdin("e").stdin("1").stdin("p").stdout()
    if not match(expected, actual):
        raise check50.Mismatch(expected, actual)
コード例 #6
0
ファイル: __init__.py プロジェクト: hirschhorn/quiz
def raises_error_with_no_order_numbers_1():
    """raises an error when trying to print no order numbers"""
    from re import match
    expected = "--> Printing all order numbers from oldest to newest.\nError: List of order numbers is empty.\n"
    actual = check50.run("./queue").stdin("p").stdout()
    if not match(expected, actual):
        raise check50.Mismatch(expected, actual)
コード例 #7
0
ファイル: __init__.py プロジェクト: maciulaitis/uzduotys
def pvz1():
    """Gaunamas teisingas atsakymas pagal 1 pavyzdį"""
    check50.run("> U1.txt").exit(0)
    duomenys = open("U1.txt", "w")
    L = [
        "6 \n", "Petras A. Petraitis 213 15 20 00 \n",
        "Jurgis Jurgutis 221 16 12 12 \n", "Rima Joana 115 15 15 59 \n",
        "Zigmas Nosis 256 16 23 9 \n", "Roma Liepa 111 15 15 15 \n",
        "Rytis Uosis Ainis 255 16 23 9 \n", "5 \n", "256 16 43 15 5 5 5 5 \n",
        "213 15 50 10 4 0 5 3 \n", "111 16 5 35 5 4 \n",
        "255 16 55 59 5 4 3 1 \n", "115 16 42 22 2 5 \n"
    ]
    duomenys.writelines(L)
    duomenys.close()
    check50.run("> U1rez.txt").exit(0)
    check50.run("./sportas").exit(0)
    with open("U1rez.txt") as m:
        rez = m.read().split()
    ats = [
        "Merginos", "111", "Roma", "Liepa", "0", "51", "20", "115", "Rima",
        "Joana", "1", "29", "23", "Vaikinai", "256", "Zigmas", "Nosis", "0",
        "20", "6", "213", "Petras", "A.", "Petraitis", "0", "38", "10", "255",
        "Rytis", "Uosis", "Ainis", "0", "39", "50"
    ]
    if ats == rez:
        pass
    else:
        raise check50.Mismatch(ats, rez)
コード例 #8
0
def raises_error_with_no_emails_1():
    """raises an error when trying to print no emails"""
    from re import match
    expected = "--> Printing all emails from newest to oldest.\nError: Inbox is empty.\n"
    actual = check50.run("./stack").stdin("print").stdout()
    if not match(expected, actual):
        raise check50.Mismatch(expected, actual)
コード例 #9
0
ファイル: __init__.py プロジェクト: minprog/progik
def encrypts_BaRFoo_FeVJss():
    """encrypts "BaRFoo" as "FeVJss" using 4 as key"""
    result = uva.check50.py.run("caesar.py",
                                argv=["caesar.py", "4"],
                                stdin=["BaRFoo"])
    if not re.match(".*ciphertext:\s*FeVJss\n", result.stdout):
        raise check50.Mismatch("ciphertext: FeVJss\n", result.stdout)
コード例 #10
0
ファイル: __init__.py プロジェクト: minprog/progik
def encrypts_BARFOO_as_EDUIRR():
    """encrypts "BARFOO" as "EDUIRR" using 3 as key"""
    result = uva.check50.py.run("caesar.py",
                                argv=["caesar.py", "3"],
                                stdin=["BARFOO"])
    if not re.match(".*ciphertext:\s*EDUIRR\n", result.stdout):
        raise check50.Mismatch("ciphertext: EDUIRR\n", result.stdout)
コード例 #11
0
ファイル: __init__.py プロジェクト: minprog/progik
def encrypts_barfoo_as_yxocll():
    """encrypts "barfoo" as "yxocll" using 23 as key"""
    result = uva.check50.py.run("caesar.py",
                                argv=["caesar.py", "23"],
                                stdin=["barfoo"])
    if not re.match(".*ciphertext:\s*yxocll\n", result.stdout):
        raise check50.Mismatch("ciphertext: yxocll\n", result.stdout)
コード例 #12
0
ファイル: __init__.py プロジェクト: minprog/progik
def encrypts_a_as_b():
    """encrypts "a" as "b" using 1 as key"""
    result = uva.check50.py.run("caesar.py",
                                argv=["caesar.py", "1"],
                                stdin=["a"])
    if not re.match(".*ciphertext:\s*b\n", result.stdout):
        raise check50.Mismatch("ciphertext: b\n", result.stdout)
コード例 #13
0
ファイル: __init__.py プロジェクト: minprog/progik
def encrypts_barfoo_as_onesbb():
    """encrypts "barfoo" as "onesbb" using 65 as key"""
    result = uva.check50.py.run("caesar.py",
                                argv=["caesar.py", "65"],
                                stdin=["barfoo"])
    if not re.match(".*ciphertext:\s*onesbb\n", result.stdout):
        raise check50.Mismatch("ciphertext: onesbb\n", result.stdout)
コード例 #14
0
ファイル: __init__.py プロジェクト: minprog/progik
def mixedBaZBARFOO():
    """encrypts "BaRFoo" as "CaQGon" using "BaZ" as keyword"""
    result = uva.check50.py.run("vigenere.py",
                                argv=["vigenere.py", "BaZ"],
                                stdin=["BaRFoo"])
    if not re.match(".*ciphertext:\s*CaQGon\n", result.stdout):
        raise check50.Mismatch("ciphertext: CaQGon\n", result.stdout)
コード例 #15
0
ファイル: __init__.py プロジェクト: minprog/progik
def allcapsBAZBARFOO():
    """encrypts "BARFOO" as "CAQGON" using "BAZ" as keyword"""
    result = uva.check50.py.run("vigenere.py",
                                argv=["vigenere.py", "BAZ"],
                                stdin=["BARFOO"])
    if not re.match(".*ciphertext:\s*CAQGON\n", result.stdout):
        raise check50.Mismatch("ciphertext: CAQGON\n", result.stdout)
コード例 #16
0
ファイル: __init__.py プロジェクト: cevgroup/problems
def check_single_col(actual, expected, ordered=False):
    """
    Checks for queries that return just a single column, ensures correct results.
    """

    # Make sure query returned results
    if actual is None or actual == []:
        raise check50.Failure("Query did not return results")

    # Make sure there is only a single column
    row_counts = {len(list(row.values())) for row in actual}
    if row_counts != {1}:
        raise check50.Failure("Query should only return a single column")

    # Get data from column
    try:
        result = [str(list(row.values())[0]) for row in actual]
        result = result if ordered else set(result)
    except IndexError:
        return None

    # Check column data against expected values
    expected = [str(value) for value in expected]
    if not ordered:
        expected = set(expected)
    if result != expected:
        raise check50.Mismatch("\n".join(expected), "\n".join(list(result)))
コード例 #17
0
ファイル: __init__.py プロジェクト: cevgroup/problems
def check_double_col(actual, expected, ordered=False):
    """
    Checks for queries that return just a single column, ensures correct results.
    """

    # Make sure query returned results
    if actual is None or actual == []:
        raise check50.Failure("Query did not return results")

    # Make sure there is only a single column
    row_counts = {len(list(row.values())) for row in actual}
    if row_counts != {2}:
        raise check50.Failure("Query should only return a single column")

    # Get data from column
    try:
        result = []
        for row in actual:
            values = list(row.values())
            result.append({str(values[0]), str(values[1])})
        result = result if ordered else set(result)
    except IndexError:
        return None

    # Check column data against expected values
    if result != expected:
        raise check50.Mismatch(
            "\n".join([str(entry) for entry in list(expected)]),
            "\n".join([str(entry) for entry in list(result)]))
コード例 #18
0
ファイル: __init__.py プロジェクト: minprog/progik
def bazworld():
    """encrypts "world!$?" as "xoqmd!$?" using "baz" as keyword"""
    result = uva.check50.py.run("vigenere.py",
                                argv=["vigenere.py", "baz"],
                                stdin=["world!$?"])
    if not re.match(".*ciphertext:\s*xoqmd!\$\?\n", result.stdout):
        raise check50.Mismatch("ciphertext: xoqmd!$?\n", result.stdout)
コード例 #19
0
ファイル: __init__.py プロジェクト: minprog/progik
def withspaces():
    """encrypts "hello, world!" as "iekmo, vprke!" using "baz" as keyword"""
    result = uva.check50.py.run("vigenere.py",
                                argv=["vigenere.py", "baz"],
                                stdin=["hello, world!"])
    if not re.match(".*ciphertext:\s*iekmo, vprke\!\n", result.stdout):
        raise check50.Mismatch("ciphertext: iekmo, vprke!\n", result.stdout)
コード例 #20
0
def occurance_words(out):
    """correct occurance of top five positive words."""
    for word, occ in [("great", 245), ("trump", 88), ("thank", 82),
                      ("good", 55), ("honor", 39)]:
        match = re.search(f"{word}[^\n^\d]*(\d+)", out)
        if not match.groups() or not int(match.groups()[0]) == occ:
            raise check50.Mismatch(f"{word} {occ}", out)
コード例 #21
0
def correct_show():
    """show() shows puzzle1 correctly"""
    module = uva.check50.py.run("sudoku.py").module

    sudoku = module.load("easy/puzzle1.sudoku")

    check_sudoku(sudoku)

    with uva.check50.py.capture_stdout() as out:
        module.show(sudoku)
        actual = [line.strip() for line in out.getvalue().split("\n")]

    expected = [
        "7 9 _  [ ]*_ _ _  [ ]*3 _ 1", "_ _ _  [ ]*_ _ 6  [ ]*9 _ _",
        "8 _ _  [ ]*_ 3 _  [ ]*_ 7 6", "", "_ _ _  [ ]*_ _ 5  [ ]*_ _ 2",
        "_ _ 5  [ ]*4 1 8  [ ]*7 _ _", "4 _ _  [ ]*7 _ _  [ ]*_ _ _", "",
        "6 1 _  [ ]*_ 9 _  [ ]*_ _ 8", "_ _ 2  [ ]*3 _ _  [ ]*_ _ _",
        "_ _ 9  [ ]*_ _ _  [ ]*_ 5 4"
    ]

    for actual_line, expected_line in zip(actual, expected):
        if not re.match(expected_line, actual_line):
            readable_line = expected_line.replace("[", "").replace("]",
                                                                   "").replace(
                                                                       "*", "")
            raise check50.Mismatch(readable_line, actual_line)
コード例 #22
0
ファイル: __init__.py プロジェクト: minprog/progik
def bazbarfoo_caqgon():
    """encrypts "barfoo" as "caqgon" using "baz" as keyword"""
    result = uva.check50.py.run("vigenere.py",
                                argv=["vigenere.py", "baz"],
                                stdin=["barfoo"])
    if not re.match(".*ciphertext:\s*caqgon\n", result.stdout):
        raise check50.Mismatch("ciphertext: caqgon\n", result.stdout)
コード例 #23
0
ファイル: __init__.py プロジェクト: minprog/progik
def aa():
    """encrypts "a" as "a" using "a" as keyword"""
    result = uva.check50.py.run("vigenere.py",
                                argv=["vigenere.py", "a"],
                                stdin=["a"])
    if not re.match(".*ciphertext:\s*a\n", result.stdout):
        raise check50.Mismatch("ciphertext: a\n", result.stdout)
コード例 #24
0
ファイル: __init__.py プロジェクト: hirschhorn/quiz
def rejects_negative_order_numbers():
    """does not enqueue a negative order number"""
    from re import match
    expected = "--> Printing all order numbers from oldest to newest.\nOrder #1\n"
    actual = check50.run("./queue").stdin("e").stdin("-1").stdin("1").stdin(
        "p").stdout()
    if not match(expected, actual):
        raise check50.Mismatch(expected, actual)
コード例 #25
0
ファイル: __init__.py プロジェクト: hirschhorn/quiz
def enqueues_2_dequeues_1_enqueues_1_and_prints():
    """enqueues 2 order numbers, dequeues 1 order number, enqueues another order number, and then prints"""
    from re import match
    expected = "--> Printing all order numbers from oldest to newest.\nOrder #2\nOrder #3\n"
    actual = check50.run("./queue").stdin("e").stdin("1").stdin("e").stdin(
        "2").stdin("d").stdin("e").stdin("3").stdin("p").stdout()
    if not match(expected, actual):
        raise check50.Mismatch(expected, actual)
コード例 #26
0
def import_count():
    """import.py imports the correct number of rows"""
    check50.run("python3 import.py students.csv").exit(timeout=10)
    db = SQL("sqlite:///students.db")
    actual = db.execute("SELECT COUNT(*) as count FROM students")[0]["count"]
    expected = 40
    if actual != expected:
        raise check50.Mismatch(str(expected), str(actual))
コード例 #27
0
ファイル: __init__.py プロジェクト: minprog/progik
def test420():
    """input of 4.2 yields output of 18"""
    result = uva.check50.py.run("cash.py", stdin=["4.2"])
    if not coins(18).match(result.stdout):
        help = None
        if coins(22).match(result.stdout):
            help = "did you forget to round your input to the nearest cent?"
        raise check50.Mismatch("18\n", actual, help=help)
コード例 #28
0
def pushes_2_pops_1_and_prints():
    """pushes 2 emails, pops 1 email, and then prints"""
    from re import match
    expected = "--> Printing all emails from newest to oldest.\nOhai\n"
    actual = check50.run("./stack").stdin("push").stdin("Ohai").stdin(
        "push").stdin("Rly").stdin("pop").stdin("print").stdout()
    if not match(expected, actual):
        raise check50.Mismatch(expected, actual)
コード例 #29
0
ファイル: __init__.py プロジェクト: minprog/progik
def checks_for_handling_non_alpha():
    """encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key"""
    result = uva.check50.py.run("caesar.py",
                                argv=["caesar.py", "12"],
                                stdin=["world, say hello!"])
    if not re.match(".*ciphertext:\s*iadxp, emk tqxxa!\n", result.stdout):
        raise check50.Mismatch("ciphertext: iadxp, emk tqxxa!\n",
                               result.stdout)
コード例 #30
0
ファイル: __init__.py プロジェクト: merunga/labs
def check_single_cell(actual, expected, floating=False):
    if floating:
        if len(actual) != 1 or len(actual[0]) != 1:
            raise check50.Failure("Query should only return a single column and single cell")
        if abs(float(list(actual[0].values())[0]) - float(expected)) > 0.01:
            raise check50.Mismatch("\n".join(expected), str(actual))
        return
    return check_single_col(actual, [expected], ordered=True)