Simple task
This commit is contained in:
parent
d6adac69ab
commit
c9ca856d8f
54
Codeforces.Console/IOTester.cs
Normal file
54
Codeforces.Console/IOTester.cs
Normal file
@ -0,0 +1,54 @@
|
||||
namespace Codeforces
|
||||
{
|
||||
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 "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return stdOut.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static string[] GetOutputLines()
|
||||
{
|
||||
return GetOutput().Split(Environment.NewLine);
|
||||
}
|
||||
|
||||
public static IList<string> GetOutputLinesAsList()
|
||||
{
|
||||
return new List<string>(GetOutputLines());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1,17 @@
|
||||
// See https://aka.ms/new-console-template for more information
|
||||
Console.WriteLine("Hello, World!");
|
||||
namespace Codeforces
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int count = int.Parse(Console.ReadLine()!);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var numbers = Console.ReadLine()!
|
||||
.Split(' ')
|
||||
.Select(x => int.Parse(x));
|
||||
Console.WriteLine(numbers.Sum());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
40
Codeforces.Test/Tests.cs
Normal file
40
Codeforces.Test/Tests.cs
Normal file
@ -0,0 +1,40 @@
|
||||
namespace Codeforces.Test;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
[Fact]
|
||||
public void TestIO()
|
||||
{
|
||||
IOTester.Start();
|
||||
|
||||
string[] input = new string[]
|
||||
{
|
||||
"5",
|
||||
"256 42",
|
||||
"1000 1000",
|
||||
"-1000 1000",
|
||||
"-1000 1000",
|
||||
"20 22"
|
||||
};
|
||||
IOTester.SetInput(input);
|
||||
|
||||
Program.Main(new string[0]);
|
||||
|
||||
string[] output = new string[]
|
||||
{
|
||||
"298",
|
||||
"2000",
|
||||
"0",
|
||||
"0",
|
||||
"42"
|
||||
};
|
||||
|
||||
string[] actualOutput = IOTester.GetOutputLines();
|
||||
Assert.Equal(output.Length, actualOutput.Length - 1);
|
||||
for (int i = 0; i< output.Length; i++)
|
||||
{
|
||||
Assert.Equal(output[i], actualOutput[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Codeforces.Test;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1 +1,2 @@
|
||||
global using Xunit;
|
||||
global using Xunit;
|
||||
global using Codeforces;
|
Loading…
Reference in New Issue
Block a user