Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Внесли изменения в файл #25

Open
wants to merge 5 commits into
base: Darja_Goljashkina
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions BubbleSort/BubbleSort.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BubbleSort", "BubbleSort\BubbleSort.csproj", "{BAEBC175-D9F7-4975-8B11-7E2C70359D0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BAEBC175-D9F7-4975-8B11-7E2C70359D0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAEBC175-D9F7-4975-8B11-7E2C70359D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAEBC175-D9F7-4975-8B11-7E2C70359D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAEBC175-D9F7-4975-8B11-7E2C70359D0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCF0EF43-DBBE-4FAF-8C6E-8E0DACF185D7}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions BubbleSort/BubbleSort/BubbleSort.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions BubbleSort/BubbleSort/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
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>netcoreapp6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
Expand Down
20 changes: 13 additions & 7 deletions CourseApp.Tests/Module2/BubbleSortTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ namespace CourseApp.Tests.Module2
[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 Inp2 = @"3
-10 7 2";
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()
{
Expand All @@ -24,8 +28,8 @@ public void Dispose()
}

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

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

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

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

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class CountInversionsTest : 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(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
CountInversions.CountInversionsMethod();

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

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

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class MergeSortTest : IDisposable
{
private const string Inp1 = @"2
3 1";

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

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

private const string Out2 = @"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(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.MergeSortMethod();

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

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

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class PairSortTest : IDisposable
{
private const string Inp1 = @"3
20 80
30 90
25 90";

private const string Out1 = @"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)]
public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

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

// act
PairSort.PairSortMethod();

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

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

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class WarehouseTest : 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
Warehouse.WarehouseMethod();

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

Assert.Equal($"{expected}", res);
}
}
}
2 changes: 1 addition & 1 deletion CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705;</NoWarn>
</PropertyGroup>
Expand Down
40 changes: 23 additions & 17 deletions CourseApp/Module2/BubbleSort.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CourseApp.Module2
{
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 number = int.Parse(Console.ReadLine()); // int.Parse - Преобразует строковое представление числа в указанном формате в эквивалентное ему 32-битовое целое число со знаком.
string str = Console.ReadLine(); // содали строку для ввода элментов, считываем
string[] sValues = str.Split(' '); // массив строк для разделения элементов через пробел. sValues - Строковое представление элемента
int[] array = new int[number]; // содали массив размерностью, которую указали ранее в number
for (int i = 0; i < number; i++)
{
arr[i] = int.Parse(sValues[i]);
array[i] = int.Parse(sValues[i]); // перебор от первого до последнего элемента, преобразование каждого строкогого элемента в число с записью в массив
}

for (int i = 0; i < arr.Length - 1; i++)
bool flag = false;

for (int i = 0; i < array.Length - 1; 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]); // сравниваем предыдущий элемент (i) с последующим (j), если элемент массива i больше элемента массива j, то меняем элементы местами
string result = string.Join(" ", array);
Console.WriteLine(result);
flag = true;
}
}
}

string result = string.Join(" ", arr);
Console.WriteLine(result);
if (flag == false)
{
Console.WriteLine(0);
}
else
{
flag = false;
}
}
}
}
Loading