private void CheckAlmostAlwaysEquals(Rocket expectedResult, My_Bot bot, Rocket initialRocket, int times = 1000) { var successes = 0; for (var i = 0; i < times; ++i) { var actualResult = bot.GetNextMove(initialRocket); if (actualResult.Equals(expectedResult)) { ++successes; } } Assert.GreaterOrEqual(successes, 0.8 * times); }
private void ComparePerformances(My_Bot singleThreadBot, My_Bot multiThreadBot, Rocket initialRocket, int times = 40) { var successes = 0; var stopWatch = new Stopwatch(); for (var i = 0; i < times; ++i) { stopWatch.Restart(); singleThreadBot.GetNextMove(initialRocket); stopWatch.Stop(); var singleThreadBotTime = stopWatch.Elapsed; stopWatch.Restart(); multiThreadBot.GetNextMove(initialRocket); stopWatch.Stop(); var multiThreadBotTime = stopWatch.Elapsed; if (multiThreadBotTime < singleThreadBotTime) { ++successes; } } Assert.GreaterOrEqual(successes, 0.8 * times, $"Ваше решение в два потока должно работать быстрее решения в один поток в {times * 0.8} случаев из {times}"); }