def testMoveDontTargetLatestBodySegment(self): with boddle(json=self.generateMoveRequest(""" ____ Y000 0000 y___ """)): move_response = main.move() self.assertEqual('{"move": "up"}', move_response.body)
def testMoveEnemy(self): with boddle(json=self.generateMoveRequest(""" _A1a _Y__ _0__ _y__ """)): move_response = main.move() self.assertNotEqual('{"move": "up"}', move_response.body)
def testMoveCorner(self): with boddle(json=self.generateMoveRequest(""" Y___ 0___ y___ ____ """)): move_response = main.move() self.assertEqual('{"move": "right"}', move_response.body)
def testMoveTargetLatestBodySegment(self): with boddle(json=self.generateMoveRequest(""" _A_y _100 _1Y_ a1__ """)): move_response = main.move() self.assertEqual('{"move": "right"}', move_response.body)
def testMoveDontEatWhenNextToTail(self): with boddle(json=self.generateMoveRequest(""" 000_ 0_Yy 0_X0 0000 """)): move_response = main.move(traits="opp") self.assertEqual('{"move": "right"}', move_response.body)
def testMoveAvoidEnemyHead(self): with boddle(json=self.generateMoveRequest(""" __A1 _Y0a __y_ ____ """)): move_response = main.move() self.assertEqual('{"move": "down"}', move_response.body)
def testMoveAvoidTrap(self): with boddle(json=self.generateMoveRequest(""" ____y___ _00_000_ _00Y__0_ _000000_ ________ ________ ________ ________ """)): move_response = main.move() self.assertEqual('{"move": "up"}', move_response.body)
def testMoveEatWhenTrappedAndPeckish(self): move_request = self.generateMoveRequest(""" 00X_ 00Yy 0000 0000 """) move_request['you']['health'] = 15 with boddle(json=move_request): move_response = main.move() self.assertEqual('{"move": "up"}', move_response.body)
def testMoveEatWhenStarving(self): move_request = self.generateMoveRequest(""" ____ X_Yy __00 ____ """) move_request['you']['health'] = 5 with boddle(json=move_request): move_response = main.move() self.assertEqual('{"move": "left"}', move_response.body)
def test_move_responses(self): """ Test required fields in respones to `/move` POST. """ game_id = '1' paramData = { 'snakes': [{ 'taunt': 'git gud', 'name': 'my-snake', 'id': '25229082-f0d7-4315-8c52-6b0ff23fb1fb', 'health_points': 93, 'coords': [[0, 0], [0, 1], [0, 2]] }, { 'taunt': 'cash me outside', 'name': 'angry-whitegirl', 'id': 'ex-uuid', 'health_points': 93, 'coords': [[15, 14], [15, 13], [15, 12]] }], 'width': 20, 'height': 20, 'game_id': game_id, 'food': [[4, 5], [8, 9]], 'you': { 'id': '25229082-f0d7-4315-8c52-6b0ff23fb1fb', 'taunt': '1-800-267-2001 ALARMFORCE', 'name': 'sneakysnake', 'health_points': 100, 'coords': [[3, 3], [3, 4], [4, 4]] }, 'turn': 0 } headers = {'Content-Type': 'application/json'} moves = ['up', 'down', 'left', 'right'] # Create a mock Battle in the game dictionary so games seem to be in progress mock_battle = Mock() mock_battle.getNextMove.return_value = 'down' mock_battle.getTaunt.return_value = 'hi there friend' main.gameDict[game_id] = mock_battle with boddle(json=paramData, headers=headers): response = main.move() self.assertIn('move', response) self.assertIn('taunt', response) self.assertIn(response['move'], moves)
def testMoveTowardsStackedTail2(self): move_request = self.generateMoveRequest(""" 0Y__ 0y__ ____ ____ """) # Create a stacked tail, as if we just ate move_request['you']['body'].append(move_request['you']['body'][-1]) with boddle(json=move_request): move_response = main.move(traits="ins") self.assertEqual('{"move": "right"}', move_response.body)
def testMoveChooseLargerTrap(self): with boddle(json=self.generateMoveRequest(""" _0000__Y0_ 00__000_0_ 0_____0_00 0_____0__0 0_____00_0 0__y0__0_0 0___0000_0 0__000__00 00_0_0000_ _000______ """)): move_response = main.move() self.assertEqual('{"move": "down"}', move_response.body)
def testMoveIntoOpenSpace(self): with boddle(json=self.generateMoveRequest(""" __________ __________ __________ ___000____ _000_0__y_ _0__00__0_ 00__Y___0_ 0_0000_00_ 000__000__ 00________ """)): move_response = main.move() self.assertEqual('{"move": "right"}', move_response.body)
def testMoveTailInsteadOfTrap(self): with boddle(json=self.generateMoveRequest(""" ___0000___ __00__0___ _00_000___ Y0__0_____ y_000_____ 0000______ 00_00000__ 0______0__ 00000000__ __________ """)): move_response = main.move() self.assertEqual('{"move": "down"}', move_response.body)
def test_move_no_game_id(self): """ Test catching a lack of 'game_id' value in the request. """ paramData = { 'snakes': [], 'width': 20, 'height': 20, 'food': [[4, 5], [8, 9]], 'you': {}, 'turn': 0 } headers = {'Content-Type': 'application/json'} with boddle(json=paramData, headers=headers): response = main.move() # Current defined behaviour is to return no response if game_id missing self.assertEqual(response, None)
def test_move_game_not_started(self): """ Test required fields in respones to `/move` POST. """ game_id = '1' paramData = { 'snakes': [{ 'taunt': 'git gud', 'name': 'my-snake', 'id': '25229082-f0d7-4315-8c52-6b0ff23fb1fb', 'health_points': 93, 'coords': [[0, 0], [0, 1], [0, 2]] }, { 'taunt': 'cash me outside', 'name': 'angry-whitegirl', 'id': 'ex-uuid', 'health_points': 93, 'coords': [[15, 14], [15, 13], [15, 12]] }], 'width': 20, 'height': 20, 'game_id': game_id, 'food': [[4, 5], [8, 9]], 'you': { 'id': '25229082-f0d7-4315-8c52-6b0ff23fb1fb', 'taunt': '1-800-267-2001 ALARMFORCE', 'name': 'sneakysnake', 'health_points': 100, 'coords': [[3, 3], [3, 4], [4, 4]] }, 'turn': 0 } headers = {'Content-Type': 'application/json'} moves = ['up', 'down', 'left', 'right'] with boddle(json=paramData, headers=headers): response = main.move() self.assertIn('move', response) self.assertIn('taunt', response) self.assertIn(response['move'], moves)