public void ComplexTest_HighNumberOfEntries() { var elements = new Entry[10000]; for (int i = 0; i < elements.Length; i++) { elements[i] = new Entry(random.NextDouble() * 100 + 100); } AssertCount(elements); }
public void NextDouble_WithoutSeed_ReturnsValuesBetween0And1() { // Arrange var randomValues = new double[Iterations]; var rng = new DefaultRandomNumberGenerator(); // Action for (var i = 0; i < Iterations; i++) { randomValues[i] = rng.NextDouble(); } // Assert Assert.IsTrue(randomValues.All(x => x >= 0 && x < 1)); }
public void NextDouble_WithoutSeed_ReturnsEquallyDistributedValues() { // Arrange var randomValues = new double[Iterations]; var rng = new DefaultRandomNumberGenerator(); const int AcceptedDeviation = 1000; // Action for (var i = 0; i < Iterations; i++) { randomValues[i] = rng.NextDouble(); } // Assert Assert.IsTrue(randomValues.Sum() > Iterations / 2 - AcceptedDeviation); Assert.IsTrue(randomValues.Sum() < Iterations / 2 + AcceptedDeviation); }
public void NextDouble_WithSeed_ReturnsAlwaysTheSameValue() { // Arrange var randomValues = new double[Iterations]; var seed = new System.Random().Next(); // Action for (var i = 0; i < Iterations; i++) { var rng = new DefaultRandomNumberGenerator(seed); randomValues[i] = rng.NextDouble(); var a = randomValues[i]; Console.WriteLine(randomValues[i]); } // Assert Assert.IsTrue(randomValues.All(x => x == randomValues[0])); }
public void TournamentSelection_PerfTest() { var random = new DefaultRandomNumberGenerator(); var config = new EAConfiguration { TournamentSize = 20, TournamentProbability = 0.5 }; var popsize = 10000; var pop = new Population(popsize); pop.Fill(() => CreatePhenotypeMock(random.NextDouble() * 10).Object); pop.Sort(EAMode.MaximizeFitness); Console.WriteLine($"popsize = {popsize}, tournament size = {config.TournamentSize}"); var watch = new Stopwatch(); watch.Start(); #pragma warning disable CS0618 // Type or member is obsolete IParentSelection selection = new TournamentParentSelectionOld(config); #pragma warning restore CS0618 // Type or member is obsolete foreach (var selected in selection.SelectParents(pop, popsize, EAMode.MaximizeFitness, random)) { } watch.Stop(); Console.WriteLine($"old: {watch.ElapsedMilliseconds} ms"); watch.Restart(); selection = new TournamentParentSelection(config); foreach (var selected in selection.SelectParents(pop, popsize, EAMode.MaximizeFitness, random)) { } watch.Stop(); Console.WriteLine($"new: {watch.ElapsedMilliseconds} ms"); }