Last active
October 29, 2021 13:22
-
-
Save jjfiv/485dcdfa25e8986dfabe9871f1a4ba15 to your computer and use it in GitHub Desktop.
CS145 F2021 Project 6 Public
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List, Tuple, Dict | |
ROOM = { | |
"name": "basement", | |
"description": """You have found the basement of the mansion. | |
It is darker down here. | |
You get the sense a secret is nearby, but you only see the stairs you came from.""", | |
"exits": [ | |
{ | |
"destination": "entranceHall", | |
"description": "There are stairs leading up.", | |
}, | |
{ | |
"destination": "secretRoom", | |
"description": "A trapdoor was hidden amongst the dust.", | |
"hidden": True, | |
}, | |
], | |
"items": [], | |
} | |
def get_destination() -> str: | |
# Using only indexing operations (on the global ROOM)... | |
# return the "destination" of the "hidden" exit | |
# If you want to be more flexible, you can write a loop that searches through the 'exits' for a hidden one. | |
return "TODO" | |
def test_get_destination(): | |
assert get_destination() == "secretRoom" | |
def glue_two_lists(keys: list, values: list) -> dict: | |
""" | |
Create a dictionary from parallel lists of keys and values. | |
If one is longer than the other, stop early. | |
You may not use zip or dict as functions; I expect you to need range and min. | |
""" | |
output = {} | |
return output | |
def test_glue(): | |
assert glue_two_lists(["A", "B"], ["a", "b"]) == {"A": "a", "B": "b"} | |
assert glue_two_lists([1, 2, 3, 4], "ABCD") == {1: "A", 2: "B", 3: "C", 4: "D"} | |
assert glue_two_lists("longer", "short") == { | |
"l": "s", | |
"o": "h", | |
"n": "o", | |
"g": "r", | |
"e": "t", | |
} | |
def count_tuples(data: List[Tuple[str, int]]) -> Dict[str, int]: | |
counts = {} | |
# Count up the word parts in data, given their existing counts. | |
# This will be similar to the counting functions we've seen in class, but where it's been partially counted up. | |
return counts | |
def test_count_tuples(): | |
data = [("a", 3), ("b", 2), ("a", 2), ("c", 4), ("b", 3)] | |
assert count_tuples(data) == {"a": 5, "b": 5, "c": 4} | |
def find_minimum_position(xs: list) -> int: | |
# return the POSITION of the minimum element of xs | |
# try to do this without using python's min. | |
return -1 | |
def test_find_min_pos(): | |
assert find_minimum_position([]) == -1 | |
assert find_minimum_position([10, 30, 5, 22]) == 2 | |
assert find_minimum_position("ABCD") == 0 | |
def reverse_dict(forward: dict) -> dict: | |
backward = {} | |
# Don't have to worry about multiple values collding as they become keys. | |
return backward | |
def test_reverse_dict(): | |
assert reverse_dict({"a": 1, "b": 2, "c": 3}) == {1: "a", 2: "b", 3: "c"} | |
def menu_hotkeys(options: List[str]) -> Dict[str, str]: | |
""" | |
Windows menus often underline letters in their menu options that | |
correspond to their “hot-key” which, usually when pressed with | |
Control, allow you to trigger that menu item without moving the | |
mouse. | |
We’d like to choose a letter for each entry (that we haven’t picked | |
for another) that comes as early in the word as possible. | |
""" | |
hotkeys = {} | |
return hotkeys | |
def test_menu_hotkeys(): | |
assert menu_hotkeys(["First", "Second", "Third"]) == { | |
"f": "First", | |
"s": "Second", | |
"t": "Third", | |
} | |
assert menu_hotkeys(["Ax", "Ay", "Az"]) == {"a": "Ax", "y": "Ay", "z": "Az"} | |
options = ["Open", "Edit", "Save", "Save As...", "Close", "Quit"] | |
shortcuts = { | |
"o": "Open", | |
"e": "Edit", | |
"s": "Save", | |
"a": "Save As...", | |
"c": "Close", | |
"q": "Quit", | |
} | |
assert menu_hotkeys(options) == shortcuts | |
if __name__ == "__main__": | |
import pytest | |
pytest.main([__file__]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment