goodagent

Finished
1import random
2import string
3
14class Robot:
5 # Class variable to hold the pool of available names
6 _name_pool = set()
7 # Class variable to track all used names
8 _used_names = set()
9
210 def __init__(self):
3 pass
4
11 """
12 Initialize a Robot with no name.
13 """
14 self._name = None
15 # Generate name pool if it's empty
16 if not Robot._name_pool:
17 self._generate_name_pool()
18
519 @property
620 def name(self) -> str:
7 pass
8
21 """
22 Get the robot's name. If the robot doesn't have a name, assign one randomly from the pool.
23
24 Returns:
25 str: The robot's name
26 """
27 # Edge Case: Robot has no name yet, assign a new one
28 if self._name is None:
29 # Edge Case: No names available in pool
30 if not Robot._name_pool:
31 raise RuntimeError("No more names available")
32
33 # Select a random name from the pool
34 self._name = random.choice(list(Robot._name_pool))
35 # Remove the name from the pool and add to used names
36 Robot._name_pool.remove(self._name)
37 Robot._used_names.add(self._name)
38
39 return self._name
40
941 def reset(self) -> None:
10 pass
42 """
43 Reset the robot to factory settings, wiping its name.
44 The name is returned to the pool for reuse.
45 """
46 # Edge Case: Robot has a name that needs to be returned to the pool
47 if self._name is not None:
48 # Return the name to the pool and remove from used names
49 Robot._name_pool.add(self._name)
50 Robot._used_names.discard(self._name)
51 self._name = None
52
53 @classmethod
54 def _generate_name_pool(cls) -> None:
55 """
56 Generate all possible valid names (two uppercase letters followed by three digits).
57 """
58 # Edge Case: Name pool already exists
59 if cls._name_pool:
60 return
61
62 letters = string.ascii_uppercase
63 digits = string.digits
64
65 # Generate all combinations of two letters and three digits
66 for first_letter in letters:
67 for second_letter in letters:
68 for digit1 in digits:
69 for digit2 in digits:
70 for digit3 in digits:
71 name = f"{first_letter}{second_letter}{digit1}{digit2}{digit3}"
72 cls._name_pool.add(name)
73
74 # Handled Edge Cases: Robot has no name yet, No names available in pool, Robot has a name that needs to be returned to the pool, Name pool already exists
Test NameStatus
test_reset_name
Fail
test_different_robots_have_different_names
Pass
test_has_name
Pass
test_name_sticks
Pass

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