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
45 changes: 23 additions & 22 deletions CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CourseApp\CourseApp.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CourseApp\CourseApp.csproj" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
81 changes: 45 additions & 36 deletions CourseApp.Tests/Module2/BubbleSortTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,52 @@
using Xunit;
using CourseApp.Module2;

namespace CourseApp.Tests.Module2
namespace CourseApp.Tests.Module2;

[Collection("Sequential")]
public class BubbleSortTest : IDisposable
{
[Collection("Sequential")]
public class BubbleSortTest : IDisposable
private const string Inp1 = @"4
6 2 3 1";

private const string Out1 = @"2 6 3 1
2 3 6 1
2 3 1 6
2 1 3 6
1 2 3 6
";

private const string Inp2 = @"4
1 2 5 7";

private const string Out2 = @"0
";

public void Dispose()
{
private const string Inp1 = @"7
5 1 7 3 9 4 1";

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

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, "1 1 3 4 5 7 9")]
[InlineData(Inp2, "-10 2 7")]
public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

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

// act
BubbleSort.BubbleSortMethod();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Assert.Equal($"{expected}", output[0]);
}
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
BubbleSort.BubbleSortMethod();

// assert
var output = stringWriter.ToString();
Assert.Equal($"{expected}", output);
}
}
46 changes: 46 additions & 0 deletions CourseApp.Tests/Module2/CountDiffTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using CourseApp.Module2;
using Module2;

namespace CourseApp.Tests.Module2;

using System;
using System.IO;
using Xunit;

[Collection("Sequential")]
public class CountDiffTest : 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
CountDiff.Count();

// assert
var output = stringWriter.ToString();
Assert.Equal($"{expected}", output);
}
}
54 changes: 54 additions & 0 deletions CourseApp.Tests/Module2/MergeSortTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using CourseApp.Module2;

namespace CourseApp.Tests.Module2;

using System;
using System.IO;
using Xunit;

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

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

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

private const string Out2 = @"1 2 1 3
1 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)]
[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
MergeSort.Sort();

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

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

namespace CourseApp.Tests.Module2;

using System;
using System.IO;
using Xunit;

[Collection("Sequential")]
public class PairSortTest : 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
PairSort.Sort();

// assert
var output = stringWriter.ToString();
Assert.Equal($"{expected}", output);
}
}
33 changes: 17 additions & 16 deletions CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705;</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705;</NoWarn>
<LangVersion>10</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
Loading