-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathInversionCountTest.cs
More file actions
56 lines (44 loc) · 1.46 KB
/
InversionCountTest.cs
File metadata and controls
56 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace CourseApp.Tests.Module2
{
using System;
using System.Collections.Generic;
using System.IO;
using CourseApp.Module2;
using Xunit;
[Collection("Sequential")]
public class InversionCountTest : IDisposable
{
private const string Inp1 = @"1
1";
private const string Out1 = @"0";
private const string Inp2 = @"2
3 1";
private const string Out2 = @"1";
private const string Inp3 = @"5
5 4 3 2 1";
private const string Out3 = @"10";
public void Dispose()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
var standardIn = new StreamReader(Console.OpenStandardInput());
Console.SetOut(standardOut);
Console.SetIn(standardIn);
}
[Theory]
[InlineData(Inp2, Out2)]
public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);
var stringReader = new StringReader(input);
Console.SetIn(stringReader);
// act
InversionCount.CountInversion();
// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}
}
}