Turn this initialization
inside-out:
while(T > 0)
{
List<Bomb> bombs = new List<Bomb>();
while (N-- > 0)
{
bombs.Add(new Bomb(rnd.Next(0, 1000), rnd.Next(0, 1000), rnd.Next(0, 1000)));
}
testCaseList.Add(new Testcase(T, bombs));
T--;
}
Also, why not have the
Testcase
constructor take
List<Bomb>
instead of
IEnumerable<Bomb>
? It is pointlessly creating a new List.
In
Testcase
you're using
numberOfBombs
as the Test case number. Since that field
is NOT actually the number of Bombs, then rename it as what it really is!
Another possibility is to have
Testcase
's constructor take the Test case number as the only parameter, always initialize the
bombList
to an empty
List<Bomb>
and then have an
AddBomb()
method that takes an instance of
Bomb
as its parameter. Then the initialization while loop will create an instance of
Testcase
(keep a local reference to it!), create N Bomb instances passing them to the
reference_to_Testcase.AddBomb()
method as they are created,
testCaseList.Add(reference_to_Testcase)
to collect them.