Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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>
2 changes: 1 addition & 1 deletion CourseApp.Tests/Module2/BubbleSortTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Test1(string input, string expected)

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Assert.Equal($"{expected}", output[0]);
Assert.Equal($"{expected}", output[^1]);
}
}
}
59 changes: 59 additions & 0 deletions CourseApp.Tests/Module2/PairSortTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);

Assert.Equal($"{expected}", result);
}
}
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>
37 changes: 21 additions & 16 deletions CourseApp/Module2/BubbleSort.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CourseApp.Module2
Expand All @@ -8,31 +7,37 @@ public class BubbleSort
{
public static void BubbleSortMethod()
{
int n = int.Parse(Console.ReadLine());
string s = Console.ReadLine();
string[] sValues = s.Split(' ');
int[] arr = new int[n];
for (int i = 0; i < n; i++)
int[] array = new int[Convert.ToInt32(Console.ReadLine())];
string[] s = Console.ReadLine().Split(' ');
for (int i = 0; i < array.Length; i++)
{
arr[i] = int.Parse(sValues[i]);
array[i] = Convert.ToInt32(s[i]);
}

for (int i = 0; i < arr.Length - 1; i++)
StringBuilder sb = new StringBuilder();
bool swaps = false;
for (int i = 0; i < array.Length; ++i)
{
for (int j = 0; j < arr.Length - i - 1; j++)
for (int j = 0; j < array.Length - i - 1; ++j)
{
if (arr[j] > arr[j + 1])
if (array[j] > array[j + 1])
{
// int temp = arr[j];
// arr[j] = arr[j + 1];
// arr[j+1] = temp;
(arr[j], arr[j + 1]) = (arr[j + 1], arr[j]);
(array[j], array[j + 1]) = (array[j + 1], array[j]);
Console.WriteLine("{0}", sb.AppendJoin(" ", array).ToString());
sb.Clear();
swaps = true;
}
}
}

string result = string.Join(" ", arr);
Console.WriteLine(result);
if (swaps == false)
{
Console.WriteLine(0);
}
else
{
swaps = false;
}
}
}
}
44 changes: 44 additions & 0 deletions CourseApp/Module2/PairSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;

namespace Module2
{
public class PairSort
{
public static void Sort()
{
int countPair = Convert.ToInt32(Console.ReadLine());
int[,] pairs = new int[countPair, 2];
for (int i = 0; i < countPair; i++)
{
var lol = Console.ReadLine().Split(" ");
pairs[i, 0] = Convert.ToInt32(lol[0]);
pairs[i, 1] = Convert.ToInt32(lol[1]);
}

for (int i = 0; i < (pairs.Length / 2); ++i)
{
for (int j = 0; j < (pairs.Length / 2) - i - 1; ++j)
{
if (pairs[j, 1] < pairs[j + 1, 1])
{
(pairs[j, 0], pairs[j + 1, 0]) = (pairs[j + 1, 0], pairs[j, 0]);
(pairs[j, 1], pairs[j + 1, 1]) = (pairs[j + 1, 1], pairs[j, 1]);
}
else if (pairs[j, 1] == pairs[j + 1, 1])
{
if (pairs[j, 0] > pairs[j + 1, 0])
{
(pairs[j, 0], pairs[j + 1, 0]) = (pairs[j + 1, 0], pairs[j, 0]);
(pairs[j, 1], pairs[j + 1, 1]) = (pairs[j + 1, 1], pairs[j, 1]);
}
}
}
}

for (int i = 0; i < pairs.Length / 2; i++)
{
Console.WriteLine($"{pairs[i, 0]} {pairs[i, 1]}");
}
}
}
}
2 changes: 0 additions & 2 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public class Program
{
public static void Main(string[] args)
{
BubbleSort.BubbleSortMethod();

Console.WriteLine("Hello World");
}
}
Expand Down
2 changes: 1 addition & 1 deletion _stylecop/stylecop.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"documentInterfaces": false,
"companyName": "Test Company",
"copyrightText": "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).",
"xmlHeader":false
"xmlHeader": false
}
}
}