Edge cases can include scenarios where the player does not move at all, or when the player moves to a negative coordinate. Here are the extended tests:
import unittest
def calc_move(player_coordinates, step):
x_move = step[0] - player_coordinates[0]
y_move = step[1] - player_coordinates[1]
new_player_coordenates = [player_coordinates[0] + x_move, player_coordinates[1] + y_move]
return [x_move, y_move], [new_player_coordenates]
class TestCalcMove(unittest.TestCase):
def test_move_up(self):
self.assertEqual(calc_move([5, 5], [5, 6]), ([0, 1], [[5, 6]]))
def test_move_down(self):
self.assertEqual(calc_move([5, 5], [5, 4]), ([0, -1], [[5, 4]]))
def test_move_right(self):
self.assertEqual(calc_move([5, 5], [6, 5]), ([1, 0], [[6, 5]]))
def test_move_left(self):
self.assertEqual(calc_move([5, 5], [4, 5]), ([-1, 0], [[4, 5]]))
def test_move_diagonal_up_right(self):
self.assertEqual(calc_move([5, 5], [6, 6]), ([1, 1], [[6, 6]]))
def test_move_diagonal_down_left(self):
self.assertEqual(calc_move([5, 5], [4, 4]), ([-1, -1], [[4, 4]]))
# Edge cases
def test_no_movement(self):
self.assertEqual(calc_move([5, 5], [5, 5]), ([0, 0], [[5, 5]]))
def test_move_to_negative_coordinates(self):
self.assertEqual(calc_move([5, 5], [-3, -3]), ([-8, -8], [[-3, -3]]))
if __name__ == "__main__":
unittest.main()
The test_no_movement test case checks the scenario when the player does not move at all, and the test_move_to_negative_coordinates test case checks the scenario when the player moves to a negative coordinate.