Skip to content

Commit

Permalink
Fix for Issue #1562 (#1563)
Browse files Browse the repository at this point in the history
* Issue 1562 (#1562): Correct unit test "Robot_names_are_unique" to keep a reference to each generated robot.

* Update exercises/practice/robot-name/RobotNameTests.cs

* Update exercises/practice/robot-name/RobotNameTests.cs

Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
  • Loading branch information
HugoRoss and ErikSchierboom committed Sep 16, 2021
1 parent ae24f01 commit 17d0839
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions exercises/practice/robot-name/RobotNameTests.cs
Expand Up @@ -42,9 +42,12 @@ public void After_reset_the_name_is_valid()
[Fact(Skip = "Remove this Skip property to run this test")]
public void Robot_names_are_unique()
{
var names = new HashSet<string>();
for (int i = 0; i < 10_000; i++) {
const int robotsCount = 10_000;
var robots = new List<Robot>(robotsCount); // Needed to keep a reference to the robots as IDs of recycled robots may be re-issued
var names = new HashSet<string>(robotsCount);
for (int i = 0; i < robotsCount; i++) {
var robot = new Robot();
robots.Add(robot);
Assert.True(names.Add(robot.Name));
Assert.Matches(@"^[A-Z]{2}\d{3}$", robot.Name);
}
Expand Down

0 comments on commit 17d0839

Please sign in to comment.