lexicon

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). All names are unique
10 and 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
27 def _generate_name_pool(self):
28 """
29 Generate all possible valid names and shuffle them randomly.
30 """
31 # Edge Case: Handle potential memory issues with large name pool
32 # This is mitigated by the strategic plan of pre-generating names
33 for letter1 in string.ascii_uppercase:
34 for letter2 in string.ascii_uppercase:
35 for digit1 in range(10):
36 for digit2 in range(10):
37 for digit3 in range(10):
38 name = f"{letter1}{letter2}{digit1}{digit2}{digit3}"
39 Robot._name_pool.append(name)
40 random.shuffle(Robot._name_pool)
41
542 @property
643 def name(self) -> str:
7 pass
8
44 """
45 Get the robot's name. If the robot doesn't have a name yet,
46 assign one from the name pool.
47
48 Returns:
49 str: The robot's name in format of two uppercase letters
50 followed by three digits.
51 """
52 # Edge Case: Assign a name if robot doesn't have one
53 if self._name is None:
54 # Edge Case: Handle exhaustion of name pool
55 if not Robot._name_pool:
56 raise RuntimeError("No more unique names available")
57
58 self._name = Robot._name_pool.pop()
59 Robot._used_names.add(self._name)
60
61 return self._name
62
963 def reset(self) -> None:
10 pass
64 """
65 Reset the robot to its factory settings, wiping its name.
66 The name is returned to the pool for potential reuse.
67 """
68 # Edge Case: Handle reset when robot has no name
69 if self._name is not None:
70 Robot._used_names.remove(self._name)
71 # In a real implementation, we might want to add the name back to the pool
72 # For this exercise, we'll just leave it out to ensure uniqueness
73 self._name = None
74
75 # Handled Edge Cases: Initialization without name, name pool exhaustion,
76 # reset when robot has no name
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.