Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp5.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
Expand Down
41 changes: 41 additions & 0 deletions CourseApp.Tests/Module1_2/WwriteTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.IO;
using Xunit;
using CourseApp.Module1_2;

namespace CourseApp.Tests.Module1_2
{
[Collection("Sequential")]
public class WwriteTest : IDisposable
{
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("Vasya", "Hello, Vasya!")]
[InlineData("Petya", "Hello, Petya!")]
[InlineData("Olya", "Hello, Olya!")]
public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
Wwrite.WriteHello(input);

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Assert.Equal($"{expected}", output[0]);
var standardOutput = new StreamWriter(Console.OpenStandardOutput());
}
}
}
40 changes: 26 additions & 14 deletions CourseApp.Tests/Module2/BubbleSortTest.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
using System;
using System.IO;
using Xunit;
using CourseApp.Module2;

namespace CourseApp.Tests.Module2
namespace CourseApp.Tests.Module2
{
using System;
using System.IO;
using CourseApp.Module2;
using Xunit;

[Collection("Sequential")]
public class BubbleSortTest : IDisposable
{
private const string Inp1 = @"7
5 1 7 3 9 4 1";
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";

private const string Inp2 = @"3
-10 7 2";
private const string Inp2 = @"4
1 2 3 4";

private const string Out2 = @"0";

public void Dispose()
{
Expand All @@ -24,8 +33,9 @@ public void Dispose()
}

[Theory]
[InlineData(Inp1, "1 1 3 4 5 7 9")]
[InlineData(Inp2, "-10 2 7")]
[InlineData(Inp1, Out1)]
[InlineData(Inp2, Out2)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Expand All @@ -39,7 +49,9 @@ public void Test1(string input, string expected)

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Assert.Equal($"{expected}", output[0]);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
}
}
45 changes: 45 additions & 0 deletions CourseApp.Tests/Module2/InversionSTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace CourseApp.Tests.Module2
{
using System;
using System.IO;
using CourseApp.Module2;
using Xunit;

[Collection("Sequential")]
public class InversionSTest : IDisposable
{
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(Inp3, Out3)]
public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
InversionS.MergeMain();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
}
71 changes: 71 additions & 0 deletions CourseApp.Tests/Module2/MergeSorttTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
namespace CourseApp.Tests.Module2
{
using System;
using System.IO;
using CourseApp.Module2;
using Xunit;

[Collection("Sequential")]
public class MergeSorttTest : IDisposable
{
private const string Inp1 = @"1
1";

private const string Out1 = @"1";

private const string Inp2 = @"2
3 1";

private const string Out2 = @"1 2 1 3
1 3";

private const string Inp3 = @"2
3 1";

private const string Out3 = @"1 2 4 5
4 5 1 2
3 5 1 3
1 5 1 5
1 2 3 4 5";

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(new int[] { 1 }, new int[] { 2 }, new int[] { 1, 2 })]
public void TestMerge(int[] a, int[] b, int[] exp)
{
var res = MergeSort.MergeSortMethod(a, b);
Assert.Equal(exp, res);
}*/

[Theory]
[InlineData(Inp1, Out1)]
[InlineData(Inp2, Out2)]
[InlineData(Inp3, Out3)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
MergeSort.MergeMain();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
}
46 changes: 46 additions & 0 deletions CourseApp.Tests/Module2/Number_of_different_Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace CourseApp.Tests.Module2
{
using System;
using System.IO;
using CourseApp.Module2;
using Xunit;

[Collection("Sequential")]
public class Number_of_different_Test : IDisposable
{
private const string Inp1 = @"5
1 0 1 2 0";

private const string Out1 = @"3";

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
Number_of_different.ClassMainNumb();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
}
52 changes: 52 additions & 0 deletions CourseApp.Tests/Module2/Task6Sort_Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
namespace CourseApp.Tests.Module2
{
using System;
using System.IO;
using CourseApp.Module2;
using Xunit;

[Collection("Sequential")]
public class Task6Sort_Test : IDisposable
{
private const string Inp1 = @"5
1 50 3 4 3
16
1 2 3 4 5 1 3 3 4 5 5 5 5 5 4 5";

private const string Out1 = @"yes
no
no
no
yes";

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
Task6Sort.Task6_Main();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
}
60 changes: 60 additions & 0 deletions CourseApp.Tests/Module2/pairsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
namespace CourseApp.Tests.Module2
{
using System;
using System.IO;
using CourseApp.Module2;
using Xunit;

[Collection("Sequential")]
public class PairsTest : IDisposable
{
private const string Inp1 = @"3
101 80
305 90
200 14";

private const string Out1 = @"305 90
101 80
200 14";

private const string Inp2 = @"3
20 80
30 90
25 90";

private const string Out2 = @"25 90
30 90
20 80";

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)]
[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
PairsSort.PairsS();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
}
Loading