/// <summary> Selects the main branch from selected via GUI (passed with <paramref name="specification"/>) and <paramref name="availableBranches"/>. </summary> /// <param name="specification"> The search specification. </param> /// <param name="availableBranches"> Branches available after filtering with vehicle classes. </param> /// <returns></returns> private EBranch SelectMainBranch(Specification specification, IEnumerable <EBranch> availableBranches) { var mainBranch = _randomiser.GetRandom(specification.BranchSpecifications.Keys.Where(branch => branch.IsIn(availableBranches)), ERandomisationStep.MainBranchWhenSelectingByCategories); LogDebug(ECoreLogMessage.Selected.Format(mainBranch)); if (mainBranch == EBranch.None) { LogWarn(EOrganizationLogMessage.NoVehiclesAvailableFor.Format(availableBranches.StringJoin(ESeparator.CommaAndSpace))); return(EBranch.None); } return(mainBranch); }
/// <summary> Randomizes contents of the collection using the given instance of a randomizer. </summary> /// <typeparam name="T"> The type of collection elements. </typeparam> /// <param name="collection"> The collection to randomize. </param> /// <param name="randomizer"> The instance of a randomizer to randomize the collection with. </param> /// <returns></returns> public static IEnumerable <T> Randomize <T>(this IEnumerable <T> collection, IRandomiser randomizer) { var sourceList = collection.ToList(); var randomizedList = new List <T>(); while (randomizedList.Count() < collection.Count()) { var selection = randomizer.GetRandom(sourceList); randomizedList.Add(selection); sourceList.Remove(selection); } return(randomizedList); }
public void GetRandom_MustReturnEdgeCases() { // arrange var observationCount = 1_000_000; var minimumValue = 0; var count = 100; var numbers = Enumerable.Range(minimumValue, count); var selectedNumbers = new List <double>(); // act for (var observationNumber = 0; observationNumber < observationCount; observationNumber++) { selectedNumbers.Add(_randomizer.GetRandom(numbers)); } // assert selectedNumbers.Should().Contain(numbers.First()); selectedNumbers.Should().Contain(numbers.Last()); }