#!/usr/bin/env python3 """ Unit tests for Map class functions: enemy_to_walls and choose_enemy. """ import sys import os sys.path.append(os.path.dirname(__file__)) from server import Map, world from lib.game_engine import GameMap def test_enemy_to_walls(): """Test enemy_to_walls function.""" # Mock world with walls world.walls = {(0, 0), (5, 5), (10, 10)} world.width = 20 world.height = 20 my_map = Map() # Test case 1: enemy at (0, 0), nearest wall is itself assert my_map.enemy_to_walls(0, 0) == 0 # Test case 2: enemy at (1, 1), distance to (0,0) is 2 assert my_map.enemy_to_walls(1, 1) == 2 # Test case 3: enemy at (6, 6), distance to (5,5) is 2 assert my_map.enemy_to_walls(6, 6) == 2 # Test case 4: enemy at (15, 15), distance to (10,10) is 10 assert my_map.enemy_to_walls(15, 15) == 10 print("test_enemy_to_walls passed!") def test_choose_enemy(): """Test choose_enemy function logic without full map.""" # Mock world world.walls = {(0, 0), (19, 19)} world.width = 20 world.height = 20 my_map = Map() my_map.width = 20 my_map.height = 20 # Mock my_side_is_left global my_side_is_left my_side_is_left = True # Left side enemy_positions = [(5, 5)] # Only one enemy to avoid complexity # Since length function is complex, we'll just check that the function runs without error # and returns the expected type result = my_map.choose_enemy(2, 2, enemy_positions) assert isinstance(result, tuple), "Should return a tuple" assert len(result) == 2, "Tuple should have 2 elements" print(f"choose_enemy returned: {result}") print("test_choose_enemy passed!") if __name__ == "__main__": test_enemy_to_walls() test_choose_enemy() print("All tests passed!")