armor

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). Names are unique and
10 randomly assigned from a pre-generated pool.
11 """
12
13 # Class variable to hold the pool of all possible names
14 _name_pool = []
15 # Class variable to track used names
16 _used_names = set()
17
218 def __init__(self):
3 pass
4
19 """
20 Initialize a new Robot instance with no name.
21 """
22 # Edge Case: Initialize name pool if it's empty
23 if not Robot._name_pool:
24 self._generate_name_pool()
25 self._name = None
26 # Edge Case: Handle case when all names are used
27 if len(Robot._used_names) >= len(Robot._name_pool):
28 raise RuntimeError("All possible robot names have been used.")
29 self.reset()
30
531 @property
632 def name(self) -> str:
7 pass
8
33 """
34 Get the robot's name.
35
36 Returns:
37 str: The robot's name in format of two uppercase letters followed by three digits.
38 """
39 return self._name
40
941 def reset(self) -> None:
10 pass
42 """
43 Reset the robot to factory settings, assigning a new random name.
44
45 This method removes the current name from the used names set (if any),
46 and assigns a new unique name from the pool.
47 """
48 # Edge Case: Remove current name from used names if it exists
49 if self._name:
50 Robot._used_names.discard(self._name)
51
52 # Edge Case: Handle case when all names are used
53 if len(Robot._used_names) >= len(Robot._name_pool):
54 raise RuntimeError("All possible robot names have been used.")
55
56 # Find an unused name
57 while True:
58 candidate = random.choice(Robot._name_pool)
59 if candidate not in Robot._used_names:
60 self._name = candidate
61 Robot._used_names.add(self._name)
62 break
63
64 @classmethod
65 def _generate_name_pool(cls):
66 """
67 Generate all possible robot names and shuffle them randomly.
68
69 This method creates a pool of 676,000 unique names in the format
70 of two uppercase letters followed by three digits.
71 """
72 # Edge Case: Only generate if pool is empty
73 if not cls._name_pool:
74 names = []
75 for first_letter in string.ascii_uppercase:
76 for second_letter in string.ascii_uppercase:
77 for number in range(1000):
78 names.append(f"{first_letter}{second_letter}{number:03d}")
79 random.shuffle(names)
80 cls._name_pool = names
81
82 # Handled Edge Cases: Initialize name pool if empty, handle all names used
83 # Handled Edge Cases: Remove current name from used names, handle all names used
84 # Handled Edge Cases: Only generate if pool is empty
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.