jackson

Finished
1import random
2import string
3
14class Robot:
5 # Class variable to hold the pre-generated name pool and current index
6 _name_pool = []
7 _current_index = 0
8
29 def __init__(self):
3 pass
4
10 # Edge Case: Initialize the name pool if it's empty (first robot creation)
11 if not Robot._name_pool:
12 Robot._generate_name_pool()
13
14 self._name = None
15 # Edge Case: Handle the case where all possible names are exhausted
16 if Robot._current_index >= len(Robot._name_pool):
17 raise RuntimeError("All possible robot names have been exhausted.")
18
19 # Assign the next name from the pool
20 self._name = Robot._name_pool[Robot._current_index]
21 Robot._current_index += 1
22
523 @property
624 def name(self) -> str:
7 pass
8
25 # Edge Case: Return the current name if it exists
26 if self._name is None:
27 raise RuntimeError("Robot name is not set.")
28 return self._name
29
930 def reset(self) -> None:
10 pass
31 # Edge Case: Handle reset when all possible names are exhausted
32 if Robot._current_index >= len(Robot._name_pool):
33 raise RuntimeError("All possible robot names have been exhausted.")
34
35 # Wipe the current name and assign a new one
36 self._name = Robot._name_pool[Robot._current_index]
37 Robot._current_index += 1
38
39 @classmethod
40 def _generate_name_pool(cls):
41 """Generate all possible robot names and shuffle them randomly."""
42 # Edge Case: Handle potential memory issues during name generation
43 try:
44 names = []
45 for first_letter in string.ascii_uppercase:
46 for second_letter in string.ascii_uppercase:
47 for number in range(1000):
48 names.append(f"{first_letter}{second_letter}{number:03d}")
49
50 # Shuffle the names randomly
51 random.shuffle(names)
52 cls._name_pool = names
53 except MemoryError:
54 raise RuntimeError("Not enough memory to generate the robot name pool.")
55
56 # Handled Edge Cases: Empty name pool initialization, exhausted names, None name access, memory issues during generation
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.