viola

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 across all robot instances
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 this is the first robot being created, generate and shuffle the name pool.
21 Assign the first available name from the pool.
22 """
23 # Edge Case: First robot initialization - generate and shuffle the name pool
24 if not Robot._name_pool:
25 self._generate_name_pool()
26
27 # Edge Case: Exhausted name pool - raise an exception as no more names are available
28 if Robot._current_index >= len(Robot._name_pool):
29 raise Exception("No more names available")
30
31 self._name = Robot._name_pool[Robot._current_index]
32 Robot._current_index += 1
33
534 @property
635 def name(self) -> str:
7 pass
8
36 """
37 Get the robot's current name.
38
39 Returns:
40 str: The robot's name in format of two uppercase letters followed by three digits.
41 """
42 return self._name
43
944 def reset(self) -> None:
10 pass
45 """
46 Reset the robot to factory settings, wiping its name.
47
48 The robot will receive a new unique name from the pool when accessed next.
49 """
50 # Edge Case: Exhausted name pool during reset - raise an exception as no more names are available
51 if Robot._current_index >= len(Robot._name_pool):
52 raise Exception("No more names available")
53
54 self._name = Robot._name_pool[Robot._current_index]
55 Robot._current_index += 1
56
57 @classmethod
58 def _generate_name_pool(cls):
59 """
60 Generate all possible valid robot names and shuffle them randomly.
61
62 This method is called once to create a pool of all possible names in the format
63 of two uppercase letters followed by three digits.
64 """
65 # Edge Case: Name format requirements - generate names with exactly 2 letters and 3 digits
66 for letter1 in string.ascii_uppercase:
67 for letter2 in string.ascii_uppercase:
68 for digit1 in string.digits:
69 for digit2 in string.digits:
70 for digit3 in string.digits:
71 cls._name_pool.append(f"{letter1}{letter2}{digit1}{digit2}{digit3}")
72
73 # Shuffle the name pool to ensure randomness
74 random.shuffle(cls._name_pool)
75
76 # Handled Edge Cases: First robot initialization, exhausted name pool, name format requirements
77
78# Handled Edge Cases: First robot initialization, exhausted name pool during reset, name format requirements
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.