| 1 | import unittest | |
| 2 | import re | |
| 3 | from main import Robot | |
| 4 | ||
| 5 | class ComprehensiveTestRobot(unittest.TestCase): | |
| 6 | def test_name_format(self): | |
| 7 | """Test that generated names follow the correct format: two uppercase letters followed by three digits""" | |
| 8 | robot = Robot() | |
| 9 | name = robot.name | |
| 10 | self.assertEqual(len(name), 5) | |
| 11 | self.assertTrue(name[:2].isalpha()) | |
| 12 | self.assertTrue(name[2:].isdigit()) | |
| 13 | self.assertEqual(name[:2], name[:2].upper()) | |
| 14 | ||
| 15 | def test_name_uniqueness_across_many_robots(self): | |
| 16 | """Test that names are unique across many robot instances""" | |
| 17 | names = set() | |
| 18 | for _ in range(1000): | |
| 19 | robot = Robot() | |
| 20 | name = robot.name | |
| 21 | self.assertNotIn(name, names, f"Duplicate name found: {name}") | |
| 22 | names.add(name) | |
| 23 | ||
| 24 | def test_reset_releases_name_for_reuse(self): | |
| 25 | """Test that resetting a robot releases its name for potential reuse""" | |
| 26 | # Create a robot and get its name | |
| 27 | robot1 = Robot() | |
| 28 | name1 = robot1.name | |
| 29 | ||
| 30 | # Reset the robot | |
| 31 | robot1.reset() | |
| 32 | ||
| 33 | # Create many new robots to potentially reuse the name | |
| 34 | # This test might not always catch reuse due to randomness, but it should not fail | |
| 35 | names = set() | |
| 36 | for _ in range(100): | |
| 37 | robot = Robot() | |
| 38 | name = robot.name | |
| 39 | names.add(name) | |
| 40 | ||
| 41 | # Theoretically, the reset name could be reused, but we can't guarantee it due to randomness | |
| 42 | # This test mainly ensures no errors occur | |
| 43 | ||
| 44 | def test_multiple_resets(self): | |
| 45 | """Test that a robot can be reset multiple times and gets new names each time""" | |
| 46 | robot = Robot() | |
| 47 | names = set() | |
| 48 | ||
| 49 | # Generate and collect 10 names through reset cycles | |
| 50 | for _ in range(10): | |
| 51 | name = robot.name | |
| 52 | self.assertNotIn(name, names) | |
| 53 | names.add(name) | |
| 54 | robot.reset() | |
| 55 | # Verify name is cleared | |
| 56 | self.assertIsNone(robot._name) | |
| 57 | ||
| 58 | def test_concurrent_access_consistency(self): | |
| 59 | """Test that accessing name multiple times returns the same value""" | |
| 60 | robot = Robot() | |
| 61 | name1 = robot.name | |
| 62 | name2 = robot.name | |
| 63 | name3 = robot.name | |
| 64 | self.assertEqual(name1, name2) | |
| 65 | self.assertEqual(name2, name3) | |
| 66 | ||
| 67 | if __name__ == "__main__": | |
| 68 | unittest.main() |
| Test Name | Status |
|---|---|
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.