weekends

Finished
1import random
2import string
3import time
4
15class Robot:
6 """
7 A class representing a robot with a randomly generated name.
8
9 The robot's name consists of two uppercase letters followed by three digits.
10 Names are unique and randomly generated upon first access or after a reset.
11 """
12
13 # Class-level set to track all generated names for uniqueness
14 _used_names = set()
15
216 def __init__(self):
3 pass
4
17 """
18 Initialize a Robot instance with no name.
19 The name will be generated when first accessed.
20 """
21 self._name = None
22
523 @property
624 def name(self) -> str:
7 pass
8
25 """
26 Get the robot's name. If the robot doesn't have a name yet,
27 generate a unique random name in the format of two uppercase letters
28 followed by three digits.
29
30 Returns:
31 str: The robot's unique name
32 """
33 # Edge Case: Robot has no name yet - generate a new one
34 if self._name is None:
35 self._generate_unique_name()
36 return self._name
37
938 def reset(self) -> None:
10 pass
39 """
40 Reset the robot to factory settings by wiping its name.
41 The next access to the name property will generate a new unique name.
42 """
43 # Edge Case: Robot has a name that needs to be removed from the used set
44 if self._name is not None:
45 Robot._used_names.discard(self._name)
46 self._name = None
47
48 def _generate_unique_name(self) -> None:
49 """
50 Generate a unique name for the robot and store it.
51
52 The name format is two uppercase letters followed by three digits.
53 This method ensures uniqueness by checking against all previously
54 generated names.
55 """
56 # Edge Case: Handle potential name collision through retries
57 max_attempts = 1000 # Prevent infinite loop in case of issues
58 for _ in range(max_attempts):
59 # Generate two random uppercase letters
60 letters = ''.join(random.choices(string.ascii_uppercase, k=2))
61
62 # Generate three random digits
63 digits = ''.join(random.choices(string.digits, k=3))
64
65 # Combine to form the name
66 new_name = letters + digits
67
68 # Check if this name is unique
69 if new_name not in Robot._used_names:
70 Robot._used_names.add(new_name)
71 self._name = new_name
72 return
73
74 # Edge Case: Exceeded maximum attempts to generate unique name
75 # This should practically never happen given the large name space (26*26*10*10*10 = 676,000 possible names)
76 raise RuntimeError("Unable to generate a unique name after maximum attempts")
77
78# Handled Edge Cases: Robot has no name yet, Robot has a name that needs to be removed from the used set, Handle potential name collision through retries, Exceeded maximum attempts to generate unique name
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.