agent

Finished
1import random
2import string
3
14class Robot:
5 """
6 A class representing a robot with a randomly assigned name.
7
8 The robot's name is generated in the format of two uppercase letters
9 followed by three digits (e.g., RX837 or BC811). Each robot has a unique name.
10
11 Attributes:
12 _name (str): The robot's current name. None if not yet assigned.
13 """
14
15 # Class variable to hold all possible names
16 _name_pool = []
17
218 def __init__(self):
3 pass
4
19 """
20 Initialize a new Robot instance.
21
22 The robot starts with no name assigned.
23 """
24 self._name = None
25
526 @property
627 def name(self) -> str:
7 pass
8
28 """
29 Get the robot's name.
30
31 If the robot doesn't have a name yet, assign one randomly from the pool.
32
33 Returns:
34 str: The robot's name in format of two uppercase letters followed by three digits.
35
36 Raises:
37 Exception: If all possible names have been used.
38 """
39 # Edge Case: Robot has no name assigned yet
40 if self._name is None:
41 # Edge Case: All possible names have been used
42 if not Robot._name_pool:
43 # Generate all possible names if pool is empty
44 if not hasattr(Robot, '_pool_initialized'):
45 letters = string.ascii_uppercase
46 digits = string.digits
47 Robot._name_pool = [
48 f"{l1}{l2}{d1}{d2}{d3}"
49 for l1 in letters
50 for l2 in letters
51 for d1 in digits
52 for d2 in digits
53 for d3 in digits
54 ]
55 Robot._pool_initialized = True
56
57 # Edge Case: No names left in pool after initialization
58 if not Robot._name_pool:
59 raise Exception("No more names available")
60
61 # Assign a random name from the pool
62 self._name = random.choice(Robot._name_pool)
63 Robot._name_pool.remove(self._name)
64
65 return self._name
66
967 def reset(self) -> None:
10 pass
68 """
69 Reset the robot to factory settings, wiping its name.
70
71 The name is returned to the pool of available names for future use.
72 """
73 # Edge Case: Robot has a name that needs to be returned to the pool
74 if self._name is not None:
75 # Only return the name to pool if we're managing the pool
76 if hasattr(Robot, '_pool_initialized'):
77 Robot._name_pool.append(self._name)
78
79 self._name = None
80
81 # Handled Edge Cases: Robot has no name assigned yet; All possible names have been used;
82 # No names left in pool after initialization; Robot has a name that needs to be returned to the pool
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.