示例#1
0
 def test_export(self):
     bot = BotField(Orientation.NORTH, 'Foobar')
     self.assertEqual(bot.export(), {
         FIELD_KEY: Field.BOT,
         'orientation': Orientation.NORTH,
         'name': 'Foobar'
     }, 'Bot field export')
示例#2
0
 def test_export(self):
     bot = BotField(Orientation.NORTH, 'Foobar')
     self.assertEqual(
         bot.export(), {
             FIELD_KEY: Field.BOT,
             'orientation': Orientation.NORTH,
             'name': 'Foobar'
         }, 'Bot field export')
示例#3
0
    def test_action_step_on_bot(self):
        game_map = Map(width=1, height=2)
        fake_map = [
            [BotField(Orientation.SOUTH)],
            [BotField(Orientation.NORTH)],
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map)

        with self.assertRaises(MovementError):
            game.action('bot_id', Action.STEP)
示例#4
0
    def test_action_reach_treasure(self):
        game_map = Map(width=1, height=2)
        fake_map = [
            [TreasureField()],
            [BotField(Orientation.NORTH)],
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map)

        with self.assertRaises(GameFinished):
            game.action('bot_id', Action.STEP)
示例#5
0
    def test_action_simple_movements(self):
        game_map = Map(width=1, height=1)
        fake_map = [
            [BotField(Orientation.EAST), EmptyField()],
            [EmptyField(), EmptyField()],
        ]
        setattr(game_map, '_{}__map'.format(game_map.__class__.__name__), fake_map)
        game = Game(game_map)
        game._empty_bots_positions = game._map.get_field_occurrences(BotField)

        self.assertFalse(game.is_filled, 'Game has free bot field.')

        fake_bot_id = 'fake_bot_id'

        game.action(fake_bot_id, Action.TURN_RIGHT)
        self.assertEqual(
            game._map[game._bots_positions[fake_bot_id]].orientation,
            Orientation.SOUTH
        )

        game.action(fake_bot_id, Action.TURN_LEFT)
        self.assertEqual(
            game.map[game._bots_positions[fake_bot_id]].orientation,
            Orientation.EAST
        )

        game.action(fake_bot_id, Action.STEP)
        self.assertEqual(
            game._bots_positions[fake_bot_id],
            (1, 0)
        )

        with self.assertRaises(MovementError):
            game.action(fake_bot_id, Action.STEP)
        self.assertEqual(
            game._bots_positions[fake_bot_id],
            (1, 0)
        )

        game.action(fake_bot_id, Action.TURN_RIGHT)

        game.action(fake_bot_id, Action.STEP)
        with self.assertRaises(MovementError):
            game.action(fake_bot_id, Action.STEP)
示例#6
0
 def test_get_next_field(self):
     game_map = Map(2, 1)
     bot = BotField()
     game_map[1, 0] = bot
     self.assertIs(game_map.get_next_field((0, 0), Orientation.EAST), bot)
     self.assertIsNone(game_map.get_next_field((0, 0), Orientation.NORTH))
示例#7
0
 def test_export(self):
     bot = BotField(Orientation.NORTH)
     self.assertEqual(bot.export(), Field.BOT, 'Bot field export')
示例#8
0
 def test_init(self):
     bot = BotField(Orientation.NORTH)
     self.assertEqual(bot.orientation, Orientation.NORTH,
                      'Bot has to save orientation.')