コード例 #1
0
    def test_do_search(self):
        game = GitCrystalsCmd()
        game.do_search('')
        expected = """In Mountain Gate you see...
    No Trespassing Sign
"""
        self.assertEqual(expected, game.output)
コード例 #2
0
    def test_display_ground(self):
        G.change_location_file("Git Crystal")

        game = GitCrystalsCmd()
        expected = "In Git Crystal you see...\n    Git Status Tutorial\n    Intro Git Tutorial\n"
        self.assertEqual(game.display_ground(), expected)

        G.change_location_file("Mountain Gate")
コード例 #3
0
 def test_create_character(self):
     G.change_location_file("Mountain Gate")
     game = GitCrystalsCmd()
     player = game.player
     self.assertEqual(player.js_location.data['location'], "Mountain Gate")
     princess = game.create_character('princess')
     self.assertEqual(princess.js_location.data['location'],
                      "Dragon's Lair")
コード例 #4
0
    def test_display_location(self):
        game = GitCrystalsCmd()
        expected = """You are in Mountain Gate
To your north is... Git Crystal
To your south is... 
To your east is... 
To your west is... 
"""
        self.assertEqual(game.display_location(), expected)
        game.do_quit('')
コード例 #5
0
    def test_do_look(self):
        G.change_location_file("Mountain Gate")
        game = GitCrystalsCmd()
        expected = """You are in Mountain Gate
To your north is... Git Crystal
To your south is... 
To your east is... 
To your west is... 
There is no here but you.
"""
        game.do_look('')
        self.assertEqual(game.output, expected)

        expected = """You are in Mountain Gate
To your north is... Git Crystal
To your south is... 
To your east is... 
To your west is... 
"""
        game.do_look('room')
        self.assertEqual(game.output, expected)

        expected = """There is no here but you.\n"""
        game.do_look('people')
        self.assertEqual(game.output, expected)
コード例 #6
0
    def test_go(self):
        G.change_location_file("Mountain Gate")
        game = GitCrystalsCmd()
        line = 'go north'
        stop = game.onecmd(line)
        game.postcmd(stop, line)
        expected_location = "Git Crystal"
        player_location = game.player.location
        json_file = JsonData(G.repodir, "location")
        file_location = json_file.data['location']

        self.assertEqual(player_location, expected_location)
        self.assertEqual(file_location, expected_location)

        G.change_location_file("Mountain Gate")
コード例 #7
0
    def test_do_perilious_search(self):
        G.change_location_file("Abandoned Treasury")
        game = GitCrystalsCmd()
        line = 'search'
        stop = game.onecmd(line)
        game.postcmd(stop, line)
        expected = """In Abandoned Treasury you see...
    Charcoal
    Treasure Chest Key
"""
        output = game.output
        alive = game.player.js_alive.data['alive']
        game.do_checkoutfile('alive.json')
        game.do_checkoutfile('location.json')

        self.assertEqual(expected, output)
        self.assertFalse(alive)
コード例 #8
0
    def test_do_drop(self):
        game = GitCrystalsCmd()

        line = 'take No Trespassing Sign'
        stop = game.onecmd(line)
        game.postcmd(stop, line)
        line = 'drop No Trespassing Sign'
        stop = game.onecmd(line)
        game.postcmd(stop, line)

        actual_inventory = game.player.js_inventory.data
        inventory_list = [("Basic Clothes", 1), ("Distress Note", 1),
                          ("Git Gem", 1)]
        expected_inventory = OrderedDict(inventory_list)
        self.assertEqual(actual_inventory, expected_inventory)
コード例 #9
0
 def test_write_data(self):
     game = GitCrystalsCmd()
     G.change_location_file('Git Crystal')
     game.load_data()
     G.change_location_file('Mountain Gate')
     game.write_data()
     file_data = JsonData(G.repodir, "location")
     self.assertEqual(file_data.data['location'], 'Git Crystal')
コード例 #10
0
    def test_display_characters(self):
        G.change_location_file("Mountain Gate")

        game = GitCrystalsCmd()
        expected = 'There is no here but you.\n'
        self.assertEqual(game.display_characters(), expected)

        G.change_location_file("Dragon's Lair")
        game = GitCrystalsCmd()
        expected = "In Dragon's Lair you see...\n    princess\n    grandfather\n    dragon\n"
        self.assertEqual(game.display_characters(), expected)

        G.change_location_file("Mountain Gate")
コード例 #11
0
    def test_loop_exit(self):
        # A do_* method exits when it returns True.
        # Game loop should end when player is dead.
        game = GitCrystalsCmd()
        game.alive.data['alive'] = True
        game.alive.write()

        game_loop_exits1 = game.do_checkoutfile('alive.json')
        game_loop_exits2 = game.do_checkout('data')
        game_loop_exits3 = game.do_checkoutforce('data')
        game_loop_exits4 = game.do_merge('data')
        game_loop_exits5 = game.do_resolveleft('alive.json')
        game_loop_exits6 = game.do_resolveright('alive.json')

        self.assertFalse(game_loop_exits1)
        self.assertFalse(game_loop_exits2)
        self.assertFalse(game_loop_exits3)
        self.assertFalse(game_loop_exits4)
        self.assertFalse(game_loop_exits5)
        self.assertFalse(game_loop_exits6)
コード例 #12
0
 def test_load_data(self):
     game = GitCrystalsCmd()
     G.change_location_file('Git Crystal')
     game.load_data()
     expected = 'Git Crystal'
     self.assertEqual(game.player.location, expected)
コード例 #13
0
 def test_display_inventory(self):
     game = GitCrystalsCmd()
     expected = "You have: \n1 of Basic Clothes\n1 of Distress Note\n1 of Git Gem\n"
     self.assertEqual(game.display_inventory(), expected)
コード例 #14
0
 def test_display_wrong_location(self):
     game = GitCrystalsCmd()
     game.player.location = "Not a location"
     expected = "You are not in a room on the world map. Try altering your location via git. \n"
     self.assertEqual(game.display_location(), expected)
コード例 #15
0
 def test_do_quit(self):
     game = GitCrystalsCmd()
     self.assertTrue(game.do_quit(''))
コード例 #16
0
 def test_do_checkoutfile(self):
     game = GitCrystalsCmd()
     game.do_north('')
     game.do_checkoutfile('location.json')
     expected = 'Mountain Gate'
     self.assertEqual(game.player.location, expected)
コード例 #17
0
    def test_do_perilious_search_with_others(self):
        G.change_location_file("Abandoned Treasury")
        G.change_character_info('princess', 'location', 'Abandoned Treasury')
        game = GitCrystalsCmd()

        line = 'search'
        stop = game.onecmd(line)
        game.postcmd(stop, line)

        output = game.output
        alive = game.player.js_alive.data['alive']
        princess_alive = game.characters['princess'].js_alive.data['alive']

        expected = """In Abandoned Treasury you see...
    Charcoal
    Treasure Chest Key\n"""

        game.do_checkoutfile('alive.json')
        game.do_checkoutfile('location.json')
        game.do_checkoutfile('princess/location.json')

        self.assertEqual(expected, output)
        self.assertFalse(alive)
        self.assertFalse(princess_alive)