Пример #1
0
    def test_sets(self):
        with captured_output() as (out, err):
            self.assertTrue(
                assert_equal({1, 5, 5, 'Test'}, {1, 5, 'test', 'test'}))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal({1, 5, 5, 'Test'}, {1, 5, 'test', 'test'}))"
            ))
        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1, 2}, {1, 2, 3}))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal({1, 2}, {1, 2, 3})), predicted answer was {1, 2, 3}, computed answer was {1, 2}."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1, 2, 3}, {1, 2, 4}))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal({1, 2, 3}, {1, 2, 4})), predicted answer was {1, 2, 4}, computed answer was {1, 2, 3}."
            ))
Пример #2
0
    def test_integers(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(5, 5))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(True, "self.assertTrue(assert_equal(5, 5))"))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(5, 10))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(5, 10)), predicted answer was 10, computed answer was 5."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(5, 10.0))

        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(5, 10.0)), predicted answer was 10.0 ('float'), computed answer was 5 ('int'). You attempted to compare unrelated data types."
            ))
Пример #3
0
    def test_strings(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal('Hello world!', 'Hello world!'))

        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal('Hello world!', 'Hello world!'))"
            ))

        with captured_output() as (out, err):
            self.assertTrue(assert_equal('Hello world!', 'Hello World!'))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal('Hello world!', 'Hello World!'))"
            ))

        with captured_output() as (out, err):
            self.assertFalse(
                assert_equal('Hello world!',
                             'Hello World!',
                             exact_strings=True))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal('Hello world!', 'Hello World!', exact_strings=True)), predicted answer was 'Hello World!', computed answer was 'Hello world!'."
            ))
Пример #4
0
    def test_sequences(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal([1, 5.0, 'Test'], [1, 5.0, 'test']))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal([1, 5.0, 'Test'], [1, 5.0, 'test']))"
            ))
        with captured_output() as (out, err):
            self.assertFalse(assert_equal([1, 2], [1, 2, 3]))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal([1, 2], [1, 2, 3])), predicted answer was [1, 2, 3], computed answer was [1, 2]."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal([1, 2, 3.0], [1, 2, 3]))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal([1, 2, 3.0], [1, 2, 3])), predicted answer was [1, 2, 3], computed answer was [1, 2, 3.0]."
            ))
    def test_floats(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(10 / 2, 5.0))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 43] self.assertTrue(assert_equal(10/2, 5.0))")

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(3.1, 3.2))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 48] self.assertFalse(assert_equal(3.1, 3.2)), predicted answer was 3.2, computed answer was 3.1."
        )
Пример #6
0
    def test_generators(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(range(5), [0, 1, 2, 3, 4]))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal(range(5), [0, 1, 2, 3, 4]))"))

        with captured_output() as (out, err):
            self.assertTrue(assert_equal([0, 1, 2, 3, 4], range(5)))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal([0, 1, 2, 3, 4], range(5)))"))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(5, range(5)))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(5, range(5))), predicted answer was range(0, 5) ('range'), computed answer was 5 ('int'). You attempted to compare unrelated data types."
            ))

        with captured_output() as (out, err):
            self.assertFalse(
                assert_equal({
                    1: 2,
                    4: 3
                }.items(), {(1, 2), (3, 4)}))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal({1: 2, 4: 3}.items(), {(1, 2), (3, 4)})), predicted answer was {(1, 2), (3, 4)}, computed answer was dict_items([(1, 2), (4, 3)])."
            ))

        with captured_output() as (out, err):
            self.assertTrue(
                assert_equal({
                    1: 2,
                    3: 4
                }.items(), {(1, 2), (3, 4)}))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal({1: 2, 3: 4}.items(), {(1, 2), (3, 4)}))"
            ))
Пример #7
0
    def test_classes(self):
        self.maxDiff = None

        class Dog:
            def __init__(self, name, breed):
                self.name = name
                self.breed = breed

            def __repr__(self):
                return self.name

        ada = Dog('ada', 'corgi')
        evil_ada = Dog('ada', 'corgi')
        my_dog = ada
        klaus = Dog('klaus', 'schnauzer')

        with captured_output() as (out, err):
            self.assertTrue(assert_equal(ada, my_dog))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(True, "self.assertTrue(assert_equal(ada, my_dog))"))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(5, my_dog))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(5, my_dog)), predicted answer was ada ('Dog'), computed answer was 5 ('int'). You attempted to compare unrelated data types."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(ada, evil_ada))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(ada, evil_ada)), predicted answer was ada, computed answer was ada."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(ada, klaus))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(ada, klaus)), predicted answer was klaus, computed answer was ada."
            ))
Пример #8
0
    def test_floats(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(10 / 2, 5.0))

        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(True, "self.assertTrue(assert_equal(10/2, 5.0))"))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(3.1, 3.2))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(3.1, 3.2)), predicted answer was 3.2, computed answer was 3.1."
            ))
    def test_frozensets(self):
        a = frozenset((1, 5, 5, 'Test'))
        b = frozenset((1, 5, 'Test', 'Test'))
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(a, b))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 191] self.assertTrue(assert_equal(a, b))")

        c = frozenset((1, 2))
        d = frozenset((1, 2, 3))
        with captured_output() as (out, err):
            self.assertFalse(assert_equal(c, d))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 198] self.assertFalse(assert_equal(c, d)), predicted answer was frozenset({1, 2, 3}), computed answer was frozenset({1, 2})."
        )
Пример #10
0
    def test_dicts(self):
        with captured_output() as (out, err):
            self.assertTrue(
                assert_equal({
                    1.0: 5,
                    'Test': True
                }, {
                    'Test': True,
                    1.0: 5
                }))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                True,
                "self.assertTrue(assert_equal({1.0: 5, 'Test': True}, {'Test': True, 1.0: 5}))"
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1: 2}, {1: 2, 3: 5}))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal({1: 2}, {1: 2, 3: 5})), predicted answer was {1: 2, 3: 5}, computed answer was {1: 2}."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1.0: 5}, {1: 5}))
        self.maxDiff = None
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal({1.0: 5}, {1: 5})), predicted answer was {1: 5}, computed answer was {1.0: 5}."
            ))

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({'Test': False}, {'Test': True}))
        self.maxDiff = None
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal({'Test': False}, {'Test': True})), predicted answer was {'Test': True}, computed answer was {'Test': False}."
            ))
Пример #11
0
    def test_frozensets(self):
        a = frozenset((1, 5, 5, 'Test'))
        b = frozenset((1, 5, 'Test', 'Test'))
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(a, b))

        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(True, "self.assertTrue(assert_equal(a, b))"))

        c = frozenset((1, 2))
        d = frozenset((1, 2, 3))
        with captured_output() as (out, err):
            self.assertFalse(assert_equal(c, d))
        self.assertRegex(
            out.getvalue().strip(),
            generate_regex(
                False,
                "self.assertFalse(assert_equal(c, d)), predicted answer was frozenset({1, 2, 3}), computed answer was frozenset({1, 2})."
            ))
    def test_integers(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal(5, 5))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 27] self.assertTrue(assert_equal(5, 5))")

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(5, 10))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 32] self.assertFalse(assert_equal(5, 10)), predicted answer was 10, computed answer was 5."
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal(5, 10.0))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 37] self.assertFalse(assert_equal(5, 10.0)), predicted answer was 10.0 ('float'), computed answer was 5 ('int'). You attempted to compare unrelated data types."
        )
    def test_traceback_shim(self):
        # Mock out traceback
        import importlib
        old = sys.modules.copy()
        sys.modules['traceback'] = None
        import cisc108

        with captured_output() as (out, err):
            self.assertTrue(cisc108.assert_equal(5, 5))
        self.assertEqual(out.getvalue().strip(), "SUCCESS")

        with captured_output() as (out, err):
            self.assertFalse(cisc108.assert_equal(5, 5.0))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE, predicted answer was 5.0 ('float'), computed answer was 5 ('int'). You attempted to compare unrelated data types."
        )

        # Restore traceback
        sys.modules['traceback'] = old['traceback']
    def test_sequences(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal([1, 5.0, 'Test'], [1, 5.0, 'test']))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 70] self.assertTrue(assert_equal([1, 5.0, 'Test'], [1, 5.0, 'test']))"
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal([1, 2], [1, 2, 3]))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 75] self.assertFalse(assert_equal([1, 2], [1, 2, 3])), predicted answer was [1, 2, 3], computed answer was [1, 2]."
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal([1, 2, 3.0], [1, 2, 3]))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 80] self.assertFalse(assert_equal([1, 2, 3.0], [1, 2, 3])), predicted answer was [1, 2, 3], computed answer was [1, 2, 3.0]."
        )
    def test_sets(self):
        with captured_output() as (out, err):
            self.assertTrue(
                assert_equal({1, 5, 5, 'Test'}, {1, 5, 'test', 'test'}))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 86] self.assertTrue(assert_equal({1, 5, 5, 'Test'}, {1, 5, 'test', 'test'}))"
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1, 2}, {1, 2, 3}))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 91] self.assertFalse(assert_equal({1, 2}, {1, 2, 3})), predicted answer was {1, 2, 3}, computed answer was {1, 2}."
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1, 2, 3}, {1, 2, 4}))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 96] self.assertFalse(assert_equal({1, 2, 3}, {1, 2, 4})), predicted answer was {1, 2, 4}, computed answer was {1, 2, 3}."
        )
    def test_dicts(self):
        with captured_output() as (out, err):
            self.assertTrue(
                assert_equal({
                    1.0: 5,
                    'Test': True
                }, {
                    'Test': True,
                    1.0: 5
                }))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 102] self.assertTrue(assert_equal({1.0: 5, 'Test': True}, {'Test': True, 1.0: 5}))"
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1: 2}, {1: 2, 3: 5}))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 107] self.assertFalse(assert_equal({1: 2}, {1: 2, 3: 5})), predicted answer was {1: 2, 3: 5}, computed answer was {1: 2}."
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({1.0: 5}, {1: 5}))
        self.maxDiff = None
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 112] self.assertFalse(assert_equal({1.0: 5}, {1: 5})), predicted answer was {1: 5}, computed answer was {1.0: 5}."
        )

        with captured_output() as (out, err):
            self.assertFalse(assert_equal({'Test': False}, {'Test': True}))
        self.maxDiff = None
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 118] self.assertFalse(assert_equal({'Test': False}, {'Test': True})), predicted answer was {'Test': True}, computed answer was {'Test': False}."
        )
    def test_strings(self):
        with captured_output() as (out, err):
            self.assertTrue(assert_equal('Hello world!', 'Hello world!'))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 54] self.assertTrue(assert_equal('Hello world!', 'Hello world!'))"
        )

        with captured_output() as (out, err):
            self.assertTrue(assert_equal('Hello world!', 'Hello World!'))
        self.assertEqual(
            out.getvalue().strip(),
            "SUCCESS - [line 59] self.assertTrue(assert_equal('Hello world!', 'Hello World!'))"
        )

        with captured_output() as (out, err):
            self.assertFalse(
                assert_equal('Hello world!',
                             'Hello World!',
                             exact_strings=True))
        self.assertEqual(
            out.getvalue().strip(),
            "FAILURE - [line 64] self.assertFalse(assert_equal('Hello world!', 'Hello World!', exact_strings=True)), predicted answer was 'Hello World!', computed answer was 'Hello world!'."
        )
Пример #18
0
# The autograder will use these to try out your game
# WIN_PATH (list[str]): A list of commands that win the game when entered
# LOSE_PATH (list[str]): A list of commands that lose the game when entered.

WIN_PATH = []
LOSE_PATH = []
    
###### 5) Unit Tests #####
# Write unit tests here

from cisc108 import assert_equal


#render_introduction
assert_equal(render_introduction(), """On a family vacation it is very difficult 
    to make everyone happy. Try to plan a day that pleases everyone, 
    "without getting too tired.""")
    
player = create_player()
# Use the built-in isinstance function to confirm that we made a dictionary
assert_equal(isinstance(player, dict), True)
# Does it have the right keys?
assert_equal(len(player.keys()), 2)
assert_equal("location" in player, True)
assert_equal(player['location'], 'yard')
assert_equal("inventory" in player, True)
assert_equal(player['inventory'], [])

world = create_world()
# Is the world a dictionary?
#assert_equal(isinstance(world, dict), True)
Пример #19
0
 def test_report_from_assert_equal(self):
     assert_equal.student_tests.reset()
     with captured_output() as (out, err):
         assert_equal(5, 10.0)
         assert_equal(5, 13.0)
         assert_equal(5, 6)
         assert_equal(5, 8)
         assert_equal(5, 5)
         assert_equal(5, 5)
     self.assertEqual(assert_equal.student_tests.tests, 6)
     self.assertEqual(assert_equal.student_tests.failures, 4)
     self.assertEqual(assert_equal.student_tests.successes, 2)
Пример #20
0
}
initial_world = {
    'turn': 'University of Delaware',
    'positions': [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
    'box': None,
    'won': [False, ''],
    'count': 0
}
################################################################################
## Testing winning_screen

# Describe this test here, then run whatever code is necessary to
# perform the tests
world['won'] = [True, 'University of Delaware']
winning_screen(world)
assert_equal(world['turn'], 'University of Delaware Wins')

world['won'] = [True, 'Villanova']
winning_screen(world)
assert_equal(world['turn'], 'Villanova Wins')

world['count'] = 9
world['won'] = [False, '']
winning_screen(world)
assert_equal(world["turn"], "It's a Tie")
assert_equal(world['won'], [True, ''])

################################################################################
## Testing update_world

################################################################################
Пример #21
0

###### 4) Win/Lose Paths #####
# The autograder will use these to try out your game
# WIN_PATH (list[str]): A list of commands that win the game when entered
# LOSE_PATH (list[str]): A list of commands that lose the game when entered.

WIN_PATH = []
LOSE_PATH = []

###### 5) Unit Tests #####
# Write unit tests here

from cisc108 import assert_equal

assert_equal("Mr. Alvey" in render_introduction(), True)
assert_equal("classroom" in render_introduction(), True)

###### 6) Main Function #####
# Do not modify this area


def main():
    '''
    Run your game using the Text Adventure console engine.
    Consumes and produces nothing, but prints and indirectly takes user input.
    '''
    print(render_introduction())
    world = create_world()
    while world['status'] == 'playing':
        print(render(world))
    This function consumes a message and converts it
    into a list of integers using a for loop and ord.
    
    Args:
        message(str): the message that the user inputs
    Returns:
        [int]: a list of integers that comes from the ord command and the for loop

    """
    new_list = []
    for character in message:
        new_list.append(ord(character))
    return new_list


assert_equal(convert_str("ABC"), [65, 66, 67])
assert_equal(convert_str("EFABC"), [69, 70, 65, 66, 67])
assert_equal(convert_str("EFDABC"), [69, 70, 68, 65, 66, 67])


def shift_list(number_list: [int], shift: int) -> [int]:
    """
    This function consumes a list of numbers and a
    shift number and shifts the list of number by that amount.
    
    Args:
        number_list([int]): consumes a list of numbers
        shift(int): consumes a number that represents the amount of shifting
    Returns:
        ([int]): returns a list of numbers that has been shifted
        
Пример #23
0
def random_chillstaff():

def create_map():
    '''
    Creates a dictionary of the world map
    
    Returns:
        Map
    '''
    return{
        'classroom' :{
            'about': 'You are at your desk in your classroom. The students are ready to learn.',
            'neighbors':['lounge','car'],
            'stuff':['ibuprofen', 'cliff bar','lotto ticket'],
            'people':random_students()
            },
        'lounge' :{
            'about': 'You sit in your regular spot and Hosner comments on your food.',
            'neighbors':['classroom'],
            'stuff':[],
            'people':['Kreitzer','Holt','Roberts','Hosner','Shaw','Dewitt','B']
            },
        'car' :{
            'about': 'you sit in your car and turn on the engine.'
            'neighbors':['lins','home'],
            'stuff':[],
            'people':[]
            },
        'lins':{
            'about': 'You put on your apron and log into your register',
            'neighbors':['car','dq'],
            'stuff':[],
            'people':['Ashlee', 'Jeff', 'Collin']
            },
        'dq':{
            'about': 'You yell for help at the dq counter.',
            'neighbors':['lins'],
            'stuff':[],
            'people':random_chillstaff()
            },
        'archam':{
           'neighbors':['home'],
            'stuff':[],
            'people':['Joker','Conselor','Batman','Gordon','Alfred']
            },
        'home':{
            'about': 'You made it home to your family. you are safe. You Win'
            'neighbors':[],
            'stuff':[],
            'people':[]
            },
        }
    
def create_player():
    '''
    Creates a dictionary of the player
    
    Returns:
        Player
    '''
    
    return {
        'location': 'classroom',
        'inventory': [],
        'hungry': False,
        'sanity': True,
        'money': 0
        }
    
    
    
def create_world():
    '''
    Creates a new version of the world in its initial state.
    
    Returns:
        World: The initial state of the world
    '''
    return {
        'map': create_map(),
        'player': create_player(),
        'status': "playing"
    }


def render(world):
    '''
    Consumes a world and produces a string that will describe the current state
    of the world. Does not print.
    
    Args:
        world (World): The current world to describe.
    
    Returns:
        str: A textual description of the world.
    '''

def get_options(world):
    '''
    Consumes a world and produces a list of strings representing the options
    that are available to be chosen given this state.
    
    Args:
        world (World): The current world to get options for.
    
    Returns:
        list[str]: The list of commands that the user can choose from.
    '''

def update(world, command):
    '''
    Consumes a world and a command and updates the world according to the
    command, also producing a message about the update that occurred. This
    function should modify the world given, not produce a new one.
    
    Args:
        world (World): The current world to modify.
    
    Returns:
        str: A message describing the change that occurred in the world.
    '''

def render_ending(world):
    '''
    Create the message to be displayed at the end of your game.
    
    Args:
        world (World): The final world state to use in describing the ending.
    
    Returns:
        str: The ending text of your game to be displayed.
    '''

def choose(options):
    '''
    Consumes a list of commands, prints them for the user, takes in user input
    for the command that the user wants (prompting repeatedly until a valid
    command is chosen), and then returns the command that was chosen.
    
    Note:
        Use your answer to Programming Problem #42.3
    
    Args:
        options (list[str]): The potential commands to select from.
    
    Returns:
        str: The command that was selected by the user.
    '''

###### 4) Win/Lose Paths #####
# The autograder will use these to try out your game
# WIN_PATH (list[str]): A list of commands that win the game when entered
# LOSE_PATH (list[str]): A list of commands that lose the game when entered.

WIN_PATH = []
LOSE_PATH = []
    
###### 5) Unit Tests #####
# Write unit tests here

from cisc108 import assert_equal

assert_equal("Mr. Alvey" in render_introduction(), True)
assert_equal("classroom" in render_introduction(), True)

###### 6) Main Function #####
# Do not modify this area

def main():
    '''
    Run your game using the Text Adventure console engine.
    Consumes and produces nothing, but prints and indirectly takes user input.
    '''
    print(render_introduction())
    world = create_world()
    while world['status'] == 'playing':
        print(render(world))
        options = get_options(world)
        command = choose(options)
        print(update(world, command))
    print(render_ending(world))

if __name__ == '__main__':
    main()
Пример #24
0
follow_sound,
revive_follower,
amulet
)

###### Unit Tests #####

#render_introduction()
assert_equal(render_introduction(), '''
                                      ==== The Impossible Journey ====
                                         ==== By: Vincent Ains ====
********************************************************************************************************************
Hello adventurer...you have quite a journey ahead of you.
There is a dangerous Dragon in her den up the path and through the magic gate.
It has been terrorizing our villages for years and now you have to kill it!
Be careful and move slowly throughout the path, once you go down it you can't go back.
You have nothing, so anything you find on your way will be helpful.
    Along the path there are secret areas that hold valuable items.
    However, not all places have them...
    Here is an amulet that can glow when there are secret places, however you can only use it 3 times
    and if you use it all in random places and find nothing...well that's on you.
Have a safe journey and kill that Dragon! By the way...DO NOT come back without the Dragon's treasure.
********************************************************************************************************************
''')

#create_player()
player = create_player()
assert_equal(isinstance(player, dict), True)
assert_equal(len(player.keys()), 6)
assert_equal("location" in player, True)
assert_equal(player['location'], 'Path A')
assert_equal("inventory" in player, True)
Пример #25
0
        },
        "Owner's Dog": {
            'neighbors': ["Dog Park"],
            "about":
            "He looks so fluffy. He is mostly black and large. He's drooling up its only because he's happy.",
            "stuff": []
        }
    }


def create_player():
    return {'location': 'bed', 'inventory': []}


player = create_player()
assert_equal(len(player.keys()), 2)
assert_equal("location" in player, True)
assert_equal(player['location'], 'bed')
assert_equal("inventory" in player, True)
assert_equal(player['inventory'], [])


def render(world):
    '''
    Consumes a world and produces a string that will describe the current state
    of the world. Does not print.
    
    Args:
        world (World): The current world to describe.
    
    Returns:
Пример #26
0

###### 4) Win/Lose Paths #####
# The autograder will use these to try out your game
# WIN_PATH (list[str]): A list of commands that win the game when entered
# LOSE_PATH (list[str]): A list of commands that lose the game when entered.

WIN_PATH = []
LOSE_PATH = []

###### 5) Unit Tests #####
# Write unit tests here

from cisc108 import assert_equal

assert_equal("Mr. Alvey" in render_introduction(), True)
assert_equal("classroom" in render_introduction(), True)

player = create_player()
# Use the built-in isinstance function to confirm that we made a dictionary
assert_equal(isinstance(player, dict), True)
# Does it have the right keys?
assert_equal(len(player.keys()), 2)
assert_equal("location" in player, True)
assert_equal(player['location'], 'classroom')
assert_equal("inventory" in player, True)
assert_equal(player['inventory'], [])
assert_equal("hungry" in player, True)
assert_equal(player['hungry'], False)
assert_equal("sanity" in player, True)
assert_equal(player['sanity'], True)
Пример #27
0
    
    Args:
        options (list[str]): The potential commands to select from.
    
    Returns:
        str: The command that was selected by the user.
    '''


###### 4) Win/Lose Paths #####
# The autograder will use these to try out your game
# WIN_PATH (list[str]): A list of commands that win the game when entered
# LOSE_PATH (list[str]): A list of commands that lose the game when entered.
player = create_player()
# Use the built-in isinstance function to confirm that we made a dictionary
assert_equal(isinstance(player, dict), True)
# Does it have the right keys?
assert_equal(len(player.keys()), 2)
assert_equal("location" in player, True)
assert_equal(player['location'], 'classroom')
assert_equal("hungry" in player, True)
assert_equal(player['hungry'], false)
assert_equal("sanity" in player, True)
assert_equal("money" in player, True)
assert_equal(player['money'], 0)

world = create_world()
# Is the world a dictionary?
assert_equal(isinstance(world, dict), True)
# Does the dictionary have the right keys?
assert_equal("status" in world)
Пример #28
0
        'user choice': None,
        'cpu choice': None,
        'score': 0,
        'Won?': None,
        'attempts': 0
    }


#I am testing every function that isn't drawing something.

################################################################################
## random_number()

# this function is supposed to generate a number from 1 to 3
for i in range(4):
    assert_equal(random_number() <= 0, False)
    assert_equal(1 <= random_number() <= 3, True)
    assert_equal(3 < random_number(), False)

#################################################################################
## handle_key()

#this function handle's how the world will respond to users
#key stoke

TEST_WORLD = make_test_world()

#sees if pressing 1 will change the user choice to santa and attempts will increase
handle_key(TEST_WORLD, ord('1'))
assert_equal(TEST_WORLD['user choice'], 'santa')
assert_equal(TEST_WORLD['attempts'], 1)