public static IEnumerable <Tuple <double, double> > Calculations(int count, IRandomNextProvider randomNextProvider, IStopWatchProvider stopWatchProvider) { var enumerable = new List <Tuple <double, double> >(); var rand = new Random(); for (var i = 0; i < count; i++) { try { var items = ReturnItems(rand.Next(1, 5), randomNextProvider).ToArray(); MakeSafe(items.ToArray(), out var elapsedMsNormal, stopWatchProvider); var resultStrength = CalculateTimings(e => e.OrderBy(y => y.Strength), items, stopWatchProvider); var resultStrengthCalc = resultStrength.Item1.Ticks / 1000d / ((elapsedMsNormal.Ticks == 0 ? 1 : elapsedMsNormal.Ticks) / 1000d); var resultWeight = CalculateTimings(e => e.OrderBy(y => y.Weight), items, stopWatchProvider); var resultWeightCalc = resultWeight.Item1.Ticks / 1000d / ((elapsedMsNormal.Ticks == 0 ? 1 : elapsedMsNormal.Ticks) / 1000d); enumerable.Add(new Tuple <double, double>(resultStrengthCalc, resultWeightCalc)); } catch (OverflowException) { } } return(enumerable); }
public HomeController(ILogger <HomeController> logger, IStopWatchViewModel stopWatchViewModel, IAthleteShuttleServices athleteShuttleServices, IStopWatchProvider stopWatchProvider, IAthleteListProvider athleteListProvider) { _logger = logger; this.stopWatchViewModel = stopWatchViewModel; this.athleteShuttleServices = athleteShuttleServices; this.stopWatchProvider = stopWatchProvider; this.athleteListProvider = athleteListProvider; this.stopWatchProvider.Shuttles = athleteShuttleServices.GetAllShuttles(); this.athleteListProvider.SetAthletes(athleteShuttleServices.GetAllAthletes()); this.athleteListProvider.SetShuttles(this.stopWatchProvider.Shuttles); }
public static Item[] MakeSafe(Item[] items, out TimeSpan elapsedMs, IStopWatchProvider stopWatchProvider) { var watch = stopWatchProvider.StartNew(); if (CheckIsSafe(items)) { watch.Stop(); elapsedMs = watch.Elapsed; return(items); } var factorial = items.Length.Factorial(); var noOfTries = 0; var sorted = false; while (!sorted) { for (var i = 0; i < items.Length; i++) { if (!CheckIsSafeIndexed(items, i)) { var temp = items[i - 1]; items[i - 1] = items[i]; items[i] = temp; } } if (CheckIsSafe(items)) { sorted = true; } if (noOfTries == factorial) { throw new OverflowException(); } noOfTries++; } watch.Stop(); elapsedMs = watch.Elapsed; return(items); }
public ProgressBarReporter(IConsoleOneLineLogger testsProgressLogger, IStopWatchProvider stopWatch) { _testsProgressLogger = testsProgressLogger; _stopWatch = stopWatch; }
public ProgressBarReporter(IProgressBar progressBar, IStopWatchProvider stopWatch, TextWriter consoleWriter = null) { _progressBar = progressBar; _stopWatch = stopWatch; _consoleWriter = consoleWriter ?? Console.Out; }
public ProgressBarReporter(IProgressBar progressBar, IStopWatchProvider stopWatch, IAnsiConsole console = null) { _progressBar = progressBar; _stopWatch = stopWatch; _console = console ?? AnsiConsole.Console; }
public static Tuple <TimeSpan, TimeSpan> CalculateTimings(Func <IEnumerable <Item>, IOrderedEnumerable <Item> > calculation, IEnumerable <Item> arg, IStopWatchProvider stopWatchProvider) { var stopWatch = stopWatchProvider.StartNew(); var output = calculation.Invoke(arg); MakeSafe(output.ToArray(), out var withoutCalcMs, stopWatchProvider); var totalMs = stopWatch.Elapsed; return(new Tuple <TimeSpan, TimeSpan>(totalMs, withoutCalcMs)); }