-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathBubbleSortTest.cs
More file actions
51 lines (43 loc) · 1.31 KB
/
BubbleSortTest.cs
File metadata and controls
51 lines (43 loc) · 1.31 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
namespace CourseApp.Tests.Module2
{
using System;
using System.Collections.Generic;
using System.IO;
using CourseApp.Module2;
using Xunit;
[Collection("Sequential")]
public class BubbleSortTest : IDisposable
{
private const string Inp1 = @"4
4 3 2 1";
private const string Out1 = @"3 4 2 1
3 2 4 1
3 2 1 4
2 3 1 4
2 1 3 4
1 2 3 4";
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(Inp1, Out1)]
public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);
var stringReader = new StringReader(input);
Console.SetIn(stringReader);
// act
BubleSort.Sort();
// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}
}
}