public String GetWidestComponent() { GoRN gorn = new GoRN(); double minWidth = this.Elements.OrderBy(_ => - _.Value.Width).First().Value.Width; var smallestComponents = this.Elements .Where(kvp => Math.Abs(kvp.Value.Width - minWidth) < Interval.MinWidth) .Select(kvp => kvp.Key) .ToList(); return(gorn.GetFromSeries(smallestComponents, 1, false).First()); }
static void TestGetFromSeries() { int[] elements = new [] { 1, 2, 3 }; int n = 5; var chosenWithReturn = new List <int>(); var chosenWithoutReturn = new List <int>(); for (int i = 0; i < N / 100; ++i) { chosenWithoutReturn.AddRange(gorn.GetFromSeries(data: elements.ToList(), n: n, withReturn: false)); chosenWithReturn.AddRange(gorn.GetFromSeries(data: elements.ToList(), n: n, withReturn: true)); } Dictionary <int, double> idealProb = new Dictionary <int, double> { { 1, 1.0 / 3.0 }, { 2, 1.0 / 3.0 }, { 3, 1.0 / 3.0 } }; Assert.True(Distance(GetProbability(chosenWithoutReturn, _ => _), idealProb) < eps); Assert.True(Distance(GetProbability(chosenWithReturn, _ => _), idealProb) < eps); }