Finished
1import random
2import string
3
14class Robot:
5 # Class variable to hold the name pool and current index
6 _name_pool = []
7 _current_index = 0
8
29 def __init__(self):
3 pass
4
10 # Edge Case: Initialize the name pool if it's empty
11 if not Robot._name_pool:
12 self._generate_name_pool()
13 random.shuffle(Robot._name_pool)
14
15 self._name = None
16 # Edge Case: Assign a name immediately upon creation
17 self._assign_name()
18
519 @property
620 def name(self) -> str:
7 pass
8
21 # Edge Case: Return the current name if it exists
22 return self._name
23
924 def reset(self) -> None:
10 pass
25 # Edge Case: Reset the robot's name to None and assign a new one
26 self._name = None
27 self._assign_name()
28
29 def _assign_name(self) -> None:
30 # Edge Case: Check if there are names available in the pool
31 if Robot._current_index >= len(Robot._name_pool):
32 raise RuntimeError("No more names available")
33
34 # Edge Case: Assign a name only if the robot doesn't have one
35 if self._name is None:
36 self._name = Robot._name_pool[Robot._current_index]
37 Robot._current_index += 1
38
39 @classmethod
40 def _generate_name_pool(cls) -> None:
41 # Generate all possible names in format: two uppercase letters + three digits
42 for first_letter in string.ascii_uppercase:
43 for second_letter in string.ascii_uppercase:
44 for number in range(1000):
45 name = f"{first_letter}{second_letter}{number:03d}"
46 cls._name_pool.append(name)
47
48# Handled Edge Cases: Empty name pool initialization, immediate name assignment upon creation, returning existing name, resetting name to None and assigning new one, checking name availability in pool, assigning name only when robot has none, generating all possible name combinations
Test NameStatus
test_different_robots_have_different_names
Pass
test_has_name
Pass
test_name_sticks
Pass
test_reset_name
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.