public void Solver_Should_GiveCorrectAnswer3() { // Arrange Solver solver = new Solver(); const string input = @"4 5 0 1 0 2 2 3 1 3 2 1"; const string expected = @"0 2 1 3 "; // Act using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(input))) using (var outMs = new MemoryStream()) { solver.Solve(ms, outMs); outMs.Position = 0; var result = new StreamReader(outMs).ReadToEnd(); // Assert Assert.That(result, Is.EqualTo(expected)); } }
public void WorstCaseScenario_Should_ReturnAnswerInResonableTime() { // Arrange const int testSize = 1000; Solver solver = new Solver(); Random rand = new Random(); List<string> input = new List<string>(testSize); StringBuilder expected = new StringBuilder("0 "); for (int i = 0; i < testSize - 1; i++) { input.Add(String.Format("{0} {1}", i, i + 1)); for (int j = i + 2; j < testSize - 2; j++) { input.Add(String.Format("{0} {1}", i, j)); } expected.Append(i + 1).Append(" "); } StringBuilder sb = new StringBuilder().AppendFormat("{0} {1}\n", testSize, input.Count); foreach (var experiment in input.OrderBy(d => rand.Next())) { sb.AppendLine(experiment); } string expectedResult = expected.ToString().TrimEnd() + "\r\n"; // Act using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()))) using (var outMs = new MemoryStream()) { Stopwatch sw = new Stopwatch(); sw.Start(); solver.Solve(ms, outMs); sw.Stop(); Debug.WriteLine("Solved in {0}", sw.Elapsed); outMs.Position = 0; var result = new StreamReader(outMs).ReadToEnd(); // Assert Assert.That(result, Is.EqualTo(expectedResult)); } }
static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(Console.OpenStandardInput(), Console.OpenStandardOutput()); }