diff --git a/Codeforces.Test/IOTester.cs b/Codeforces.Test/IOTester.cs index 68a0ebb..5834108 100644 --- a/Codeforces.Test/IOTester.cs +++ b/Codeforces.Test/IOTester.cs @@ -1,11 +1,8 @@ namespace Codeforces.Test { - public class IOTester + public class IOTester { - private static readonly TextReader originalStdIn = Console.In; private static StringReader? stdIn; - - private static readonly TextWriter originalStdOut = Console.Out; private static StringWriter? stdOut; public static void Start() @@ -14,14 +11,6 @@ namespace Codeforces.Test Console.SetOut(stdOut); } - public static void End() - { - stdOut = null; - stdIn = null; - Console.SetOut(originalStdOut); - Console.SetIn(originalStdIn); - } - public static void SetInput(params string[] lines) { string input = string.Join(Environment.NewLine, lines); @@ -29,26 +18,12 @@ namespace Codeforces.Test Console.SetIn(stdIn); } - public static string GetOutput() + public static IEnumerable GetOutputLines() { - if (stdOut == null) - { - return string.Empty; - } - else - { - return stdOut.ToString(); - } - } - - public static string[] GetOutputLines() - { - return GetOutput().Split(Environment.NewLine).SkipLast(1).ToArray(); - } - - public static IList GetOutputLinesAsList() - { - return new List(GetOutputLines()); + return stdOut?.ToString() + .Split(Environment.NewLine) + .SkipLast(1) + ?? Enumerable.Empty(); } } } \ No newline at end of file diff --git a/Codeforces.Test/Tests.cs b/Codeforces.Test/Tests.cs index a719b3b..f45b503 100644 --- a/Codeforces.Test/Tests.cs +++ b/Codeforces.Test/Tests.cs @@ -8,32 +8,28 @@ public class Tests public void TestText() { IOTester.Start(); - string[] input = new[] - { - "5", + string[] input = + [ + "5", "256 42", "1000 1000", "-1000 1000", "-1000 1000", "20 22" - }; + ]; IOTester.SetInput(input); Program.Main(); - string[] expectedOutput = new[] - { - "298", + string[] expected = + [ + "298", "2000", "0", "0", "42" - }; - string[] actualOutput = IOTester.GetOutputLines(); - Assert.Equal(expectedOutput.Length, actualOutput.Length); - for (int i = 0; i < expectedOutput.Length; i++) - { - Assert.Equal(expectedOutput[i], actualOutput[i]); - } + ]; + string[] actual = IOTester.GetOutputLines().ToArray(); + Assert.Equal(expected, actual); } [Theory] @@ -46,13 +42,9 @@ public class Tests Program.Main(); - string[] expectedOutput = File.ReadLines(output).ToArray(); - string[] actualOutput = IOTester.GetOutputLines(); - Assert.Equal(expectedOutput.Length, actualOutput.Length); - for (int i = 0; i < expectedOutput.Length; i++) - { - Assert.Equal(expectedOutput[i], actualOutput[i]); - } + var expectedOutput = File.ReadLines(output); + var actualOutput = IOTester.GetOutputLines(); + Assert.Equal(expectedOutput, actualOutput); } } public class FileNameGenerator : IEnumerable