fishlium

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 followed by three digits.
9 Names are unique and randomly assigned from a pre-generated pool.
10 """
11
12 # Class-level name pool and index to ensure uniqueness
13 _name_pool = []
14 _current_index = 0
15
216 def __init__(self):
3 pass
4
17 """
18 Initialize a new Robot instance.
19
20 If the name pool hasn't been generated yet, it creates and shuffles all possible names.
21 Then assigns a name to this robot.
22 """
23 # Edge Case: First robot initialization - generate and shuffle the name pool
24 if not Robot._name_pool:
25 # Generate all possible names (26*26*10*10*10 = 676,000 combinations)
26 for first_letter in string.ascii_uppercase:
27 for second_letter in string.ascii_uppercase:
28 for digit1 in string.digits:
29 for digit2 in string.digits:
30 for digit3 in string.digits:
31 Robot._name_pool.append(first_letter + second_letter + digit1 + digit2 + digit3)
32 # Shuffle the pool to ensure randomness
33 random.shuffle(Robot._name_pool)
34
35 # Edge Case: Exhausted name pool - this should not happen per problem constraints
36 if Robot._current_index >= len(Robot._name_pool):
37 raise RuntimeError("All possible robot names have been exhausted.")
38
39 self._name = Robot._name_pool[Robot._current_index]
40 Robot._current_index += 1
41
542 @property
643 def name(self) -> str:
7 pass
8
44 """
45 Get the robot's name.
46
47 Returns:
48 str: The robot's current name.
49 """
50 return self._name
51
952 def reset(self) -> None:
10 pass
53 """
54 Reset the robot to factory settings, wiping its name.
55
56 The robot will receive a new unique name from the pool when accessed again.
57 """
58 # Edge Case: Exhausted name pool during reset - this should not happen per problem constraints
59 if Robot._current_index >= len(Robot._name_pool):
60 raise RuntimeError("All possible robot names have been exhausted.")
61
62 self._name = Robot._name_pool[Robot._current_index]
63 Robot._current_index += 1
64
65# Handled Edge Cases: First robot initialization, exhausted name 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.