diff options
author | Serghei Cebotari <serghei@cebotari.ru> | 2023-08-11 10:09:15 +0300 |
---|---|---|
committer | Serghei Cebotari <serghei@cebotari.ru> | 2023-08-11 10:09:15 +0300 |
commit | f11270f3b5d15a4afe5026efa0c0c5406b85c3d5 (patch) | |
tree | 2941f14818b5fda624968c1abfd305e0e8d51cce /Codeforces.Test | |
parent | e4acd262c532876835efcf436744093db784f806 (diff) |
Move IOTester class
Diffstat (limited to 'Codeforces.Test')
-rw-r--r-- | Codeforces.Test/IOTester.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Codeforces.Test/IOTester.cs b/Codeforces.Test/IOTester.cs new file mode 100644 index 0000000..68a0ebb --- /dev/null +++ b/Codeforces.Test/IOTester.cs @@ -0,0 +1,54 @@ +namespace Codeforces.Test +{ + 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() + { + stdOut = new StringWriter(); + 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); + stdIn = new StringReader(input); + Console.SetIn(stdIn); + } + + public static string GetOutput() + { + 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<string> GetOutputLinesAsList() + { + return new List<string>(GetOutputLines()); + } + } +}
\ No newline at end of file |