public void DoNotSelectFirstCandidateWhenHasZeroAptitudeEvenWithZeroRouletteValue() { var itemSelector = new RouletteWheel(); var array = new Single[] { 0F, 1F, 1F, 1F, 1F }; var selected = itemSelector.SelectItem(array, 0F); Assert.That(selected, Is.Not.EqualTo(0)); }
public void SelectFourthItemWhenRouletteFallsOnTheLeftBoundaryOfTheFourthSector() { var itemSelector = new RouletteWheel(); var array = new Single[] { 1F, 1F, 0.1F, 1F, 1F }; //third/fourth boundary is 2.1 / 4.1 = 0.5121951 int?selItem = itemSelector.SelectItem(array, .5122F); Assert.That(selItem, Is.EqualTo(3)); }
public void SelectThirdItemWhenRouletteFallsOnTheLeftBoundaryOfTheThirdSector() { var itemSelector = new RouletteWheel(); var array = new Single[] { 1F, 1F, 0.1F, 1F, 1F }; //second/third boundary is 2 / 4.1 = 0.4878048 int?selItem = itemSelector.SelectItem(array, .4879F); Assert.That(selItem, Is.EqualTo(2)); }
public void ShouldSelectAnItem() { var itemSelector = new RouletteWheel(); var array = new Single[1 + rnd.Next(10)]; for (int i = 0; i < array.Length; i++) { array[i] = 1F; } var rouletteValue = (float)rnd.NextDouble(); int?selItem = itemSelector.SelectItem(array, rouletteValue); Assert.That(selItem, Is.GreaterThanOrEqualTo(0).And.LessThanOrEqualTo(array.Length)); }
public void SelectionGivesLastElementWhenRouletteValueIsGreaterThanOne() { var itemSelector = new RouletteWheel(); var elems = rnd.Next(100) + 2; var array = new Single[elems]; for (int i = 0; i < elems; i++) { array[i] = 1F; } var selected = itemSelector.SelectItem(array, 1.0001F); Assert.That(selected, Is.EqualTo(elems - 1)); }
public void ShouldSelectNoItemsWhenAptitudeAreAllZero() { var itemSelector = new RouletteWheel(); var array = new Single[1 + rnd.Next(10)]; for (int i = 0; i < array.Length; i++) { array[i] = 0F; } var rouletteValue = (float)rnd.NextDouble(); int?selItem = itemSelector.SelectItem(array, rouletteValue); Assert.That(selItem, Is.Null); }
public void ShouldSelectTheOnlyItemWithNonZeroAptitude() { var itemSelector = new RouletteWheel(); var array = new Single[1 + rnd.Next(10)]; for (int i = 0; i < array.Length; i++) { array[i] = 0F; } var nonZeroItemIndex = rnd.Next(array.Length); array[nonZeroItemIndex] = 1F; var rouletteValue = (float)rnd.NextDouble(); int?selItem = itemSelector.SelectItem(array, rouletteValue); Assert.That(selItem, Is.EqualTo(nonZeroItemIndex)); }
public void ShouldNotSelectAnItemWithZeroAptitude() { var itemSelector = new RouletteWheel(); var array = new Single[2 + rnd.Next(10)]; for (int i = 0; i < array.Length; i++) { array[i] = 1F; } var zeroItemIndex = rnd.Next(array.Length); array[zeroItemIndex] = 0F; var rouletteValue = (float)rnd.NextDouble(); int?selItem = itemSelector.SelectItem(array, rouletteValue); Assert.That(selItem, Is.GreaterThanOrEqualTo(0) .And .LessThanOrEqualTo(array.Length) .And.Not.EqualTo(zeroItemIndex)); }