Пример #1
0
def find_items():
    """Finds items in rooms."""
    check50.exists("item.py")
    # Check initial description
    try:
        check = check50.run(run_command).stdin("in")
        check.stdout(room_3_description, regex=False)

        for item in room_3_items:
            check.stdout(item, regex=False)
    except check50.Failure as error:
        raise check50.Failure("Could not find items upon first entering room.\n"
                              "    Remember to seperate multiple items by a "
                              "single newline.\n"
                              f"    {error}")

    # Check for look command
    try:
        check = check50.run(run_command)
        moves = ["IN", "OUT", "IN", "LOOK"]

        for move in moves:
            check.stdout("> ")
            check.stdin(move, prompt=False)

        for item in room_3_items:
            check.stdout(item, regex=False)
    except check50.Failure as error:
        raise check50.Failure("Could not find items when using LOOK.\n"
                              f"    {error}")
Пример #2
0
def move_once():
    """Starting Adventure then moving once to the WEST."""
    try:
        check50.run(run_command).stdout(room_1_description, regex=False)
    except check50.Failure as error:
        raise check50.Failure(f"Expected the description of initial "
                              f"room when Adventure starts.\n    {error}")
    check50.run(run_command).stdin("WEST").stdout(room_2_description,
                                                  regex=False)
Пример #3
0
def conditional_move():
    """Check if holding an item affects conditional movement."""
    check = check50.run(run_command)
    moves = ["DOWN", "DOWN", "DOWN", "DOWN"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout("The grate is locked and you don't have any keys.",
                 regex=False)

    check = check50.run(run_command)
    moves = ["IN", "TAKE keys", "OUT", "DOWN", "DOWN", "DOWN", "DOWN"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout(room_8_description, regex=False)
    for item in room_8_items:
        check.stdout(item, regex=False)

    # Check for move with multiple conditions.
    try:
        check = check50.run(run_command)
        moves = [
            "IN", "TAKE KEYS", "OUT", "DOWN", "DOWN", "DOWN", "DOWN",
            "TAKE LAMP", "IN", "WEST", "WEST", "WEST", "TAKE BIRD", "WEST",
            "DOWN", "SOUTH", "TAKE NUGGET", "OUT", "DROP NUGGET", "UP", "EAST",
            "EAST", "EAST", "TAKE ROD", "WEST", "WEST", "LOOK"
        ]

        for move in moves:
            check.stdout("> ")
            check.stdin(move, prompt=False)
        check.stdout(room_14_description, regex=False)

        moves = ["EAST", "DROP BIRD", "WEST", "LOOK"]

        for move in moves:
            check.stdout("> ")
            check.stdin(move, prompt=False)
        check.stdout(room_15_description, regex=False)

    except check50.Failure as error:
        raise check50.Failure("Did not find correct room description when "
                              "going WEST from room 13 holding either BIRD & "
                              "ROD or just ROD.\n"
                              f"    {error}")
Пример #4
0
def won():
    """Testing Crowther Adventure win condition."""
    moves = [
        "IN", "TAKE KEYS", "OUT", "DOWN", "DOWN", "DOWN", "DOWN", "TAKE LAMP",
        "IN", "WEST", "WEST", "WEST", "TAKE BIRD", "WEST", "DOWN", "SOUTH",
        "TAKE NUGGET", "OUT", "DROP NUGGET", "UP", "EAST", "EAST", "EAST",
        "TAKE ROD", "WEST", "WEST", "WEST", "DOWN", "TAKE NUGGET", "WEST",
        "WAVE", "TAKE DIAMOND", "WEST", "SOUTH", "SOUTH", "EAST", "NORTH",
        "NORTH", "TAKE CHEST", "OUT", "WEST", "DOWN", "WEST", "DOWN", "NORTH",
        "EAST", "TAKE COINS", "OUT", "NORTH", "DOWN", "EAST", "DROP LAMP",
        "DROP BIRD", "DROP NUGGET", "DROP COINS", "NORTH", "TAKE EMERALD",
        "OUT", "TAKE LAMP", "TAKE BIRD", "TAKE NUGGET", "TAKE COINS", "WEST",
        "WEST", "WEST", "DOWN", "WATER", "TAKE EGGS", "NORTH", "DOWN", "OUT",
        "EAST", "EAST", "EAST", "UP", "SOUTH", "SOUTH", "WEST", "WAVE", "WEST",
        "SOUTH", "NORTH", "NORTH", "EAST", "DOWN", "EAST", "EAST", "XYZZY",
        "NORTH"
    ]
    check = check50.run(run_command)

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout(
        "You have collected all the treasures and are admitted to "
        "the Adventurer's Hall of Fame.  Congratulations!",
        regex=False)
    check.stdout("\n")
    check.exit(0)
Пример #5
0
def helper_commands():
    """Testing helper commands; HELP, LOOK, QUIT."""
    # Test HELP
    try:
        check = check50.run(run_command).stdin("HELP")
        for help in help_statement:
            check.stdout(help)
    except check50.Failure as error:
        raise check50.Failure(f"HELP did not print the expected message.\n"
                              "    {error}")

    # Test LOOK command
    try:
        check50.run(run_command).stdin("LOOK").stdout(room_1_description,
                                                      regex=False)
        check50.run(run_command).stdin("look").stdout(room_1_description,
                                                      regex=False)
    except check50.Failure as error:
        raise check50.Failure(f"LOOK/look did not print the expected room"
                              "description.\n    {error}")

    # Test QUIT
    try:
        check50.run(run_command).stdin("QUIT").stdout("Thanks for playing!",
                                                      regex=False).exit(0)
    except check50.Failure as error:
        raise check50.Failure(f"QUIT did not function as expected.\n"
                              "    {error}")
Пример #6
0
def handle_invalid_items():
    """Take and drop nonexistent items."""
    # Take a non-existent item.
    check = check50.run(run_command).stdin("TAKE kes")
    check.stdout(no_item, regex=False)

    # Take an item twice.
    check = check50.run(run_command)
    moves = ["IN", "TAKE keys", "TAKE keys"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)
    check.stdout(no_item, regex=False)

    # Drop non-existent item.
    check = check50.run(run_command).stdin("DROP something")
    check.stdout(no_item, regex=False)
Пример #7
0
def inventory():
    """Using the INVENTORY command."""
    # Check empty inventory.
    try:
        check = check50.run(run_command).stdin("INVENTORY")
        check.stdout("Your inventory is empty", regex=False)
    except check50.Failure as error:
        raise check50.Failure(f"Let the player know they have no items.\n"
                              f"    {error}")

    # Check having keys.
    check = check50.run(run_command)
    moves = ["IN", "TAKE keys", "INVENTORY"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout("KEYS", regex=False)
    check.stdout("a set of keys", regex=False)
Пример #8
0
def forced_move():
    """Checking if FORCED immediately moves the player."""
    check = check50.run(run_command)
    moves = ["DOWN", "DOWN", "DOWN", "DOWN"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout("The grate is locked and you don't have any keys.",
                 regex=False)
    check.stdout("Outside grate", regex=False)
Пример #9
0
def conditional_move():
    """Check if holding an item affects conditional movement."""
    check = check50.run(run_command)
    moves = ["DOWN", "DOWN", "DOWN", "DOWN"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout("The grate is locked and you don't have any keys.",
                 regex=False)

    check = check50.run(run_command)
    moves = ["IN", "TAKE keys", "OUT", "DOWN", "DOWN", "DOWN", "DOWN"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout(room_8_description, regex=False)
    for item in room_8_items:
        check.stdout(item, regex=False)
Пример #10
0
def move_mixed_case():
    """Move with mixed case command."""
    check50.run(run_command).stdin("west").stdout(room_2_description,
                                                  regex=False)
    check50.run(run_command).stdin("wESt").stdout(room_2_description,
                                                  regex=False)
    check50.run(run_command).stdin("west").stdin("EAST").stdout(room_1_name,
                                                                regex=False)
Пример #11
0
def handle_items():
    """Take and drop items."""
    # Take keys check
    check = check50.run(run_command)
    moves = ["IN", "TAKE keys"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout("KEYS taken", regex=False)

    # Drop keys check then look for dropped keys check
    check = check50.run(run_command)
    moves = ["IN", "TAKE keys", "OUT", "DROP keys"]

    for move in moves:
        check.stdout("> ")
        check.stdin(move, prompt=False)

    check.stdout("KEYS dropped", regex=False)
    check.stdin("look").stdout("KEYS", regex=False)
    check.stdout("a set of keys", regex=False)
Пример #12
0
def special_move():
    """Performing special moves such as JUMP or XYZZY."""
    try:
        check = check50.run(run_command)
        moves = ["IN", "XYZZY"]

        for move in moves:
            check.stdout("> ")
            check.stdin(move, prompt=False)

        check.stdout(
            "It is now pitch dark.  If you proceed you will "
            "likely fall into a pit.",
            regex=False)
    except check50.Failure as error:
        raise check50.Failure("Could not perform XYZZY. Check "
                              "CrowtherRooms.txt for all the different"
                              "connections.")
Пример #13
0
def move_repeatedly():
    """Moving WEST, EAST, WEST in succession."""
    check = check50.run(run_command)
    check.stdin("WEST").stdout(room_2_description, regex=False)
    check.stdin("EAST").stdout(room_1_name, regex=False)
    check.stdin("WEST").stdout(room_2_name, regex=False)
Пример #14
0
def move_invalid():
    """Attempt an invalid move."""
    check50.run(run_command).stdin("EAST").stdout("Invalid command")
Пример #15
0
def commands():
    """Test if program handles invalid commands."""
    # Check invalid command
    check = check50.run(run_command).stdin("cs50")
    check.stdout("Invalid command", regex=False)
Пример #16
0
def move_invalid():
    """Attempt to move EAST into an unconnected room."""
    check50.run(run_command).stdin("EAST").stdout("Invalid command")