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
41 changes: 41 additions & 0 deletions Test2.1/Test2.1.Test/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using NUnit.Framework;
using System.Collections.Generic;

namespace Test2._1.Test
{
public class Tests
{
private List<int> listInt;

private List<string> listString;

[SetUp]
public void Setup()
{
listInt = new List<int>() { 23 , 11, 13, 43, 12, 4, 32, 1 };
listString = new List<string>() { "abc", "aa", "bb", "zv", "fe", "qwe", "123" };
}

[Test]
public void TestForInt()
{
var listCheck = new List<int>() { 43, 32, 23, 13, 12, 11, 4, 1 };
BubbleSort.Sort(listInt, new CompareIntInDescendingOrder());
for (int i = 0; i < listInt.Count; ++i)
{
Assert.AreEqual(listInt[i], listCheck[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наоборот, первый параметр --- что ожидали, второй --- что получили

}
}

[Test]
public void TestForString()
{
BubbleSort.Sort(listString, new CompareStringInDescendingOrder());
var listCheck = new List<string>() { "zv", "qwe", "fe", "bb", "abc", "aa", "123" };
for (int i = 0; i < listString.Count; ++i)
{
Assert.AreEqual(listString[i], listCheck[i]);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тестов маловато. Стоило проверить на пустом списке, на списке, где все элементы одинаковы, на null-ы в параметрах. Задача-то простая очень, время было :)

}
}
20 changes: 20 additions & 0 deletions Test2.1/Test2.1.Test/Test2.1.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Test2._1.Test</RootNamespace>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Test2.1\Test2.1.csproj" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions Test2.1/Test2.1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test2.1", "Test2.1\Test2.1.csproj", "{76CC7F56-1163-4E10-AF42-2CC237D105E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test2.1.Test", "Test2.1.Test\Test2.1.Test.csproj", "{F6F58D61-D0CB-486F-BA33-884F2589F5C9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{76CC7F56-1163-4E10-AF42-2CC237D105E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76CC7F56-1163-4E10-AF42-2CC237D105E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76CC7F56-1163-4E10-AF42-2CC237D105E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76CC7F56-1163-4E10-AF42-2CC237D105E6}.Release|Any CPU.Build.0 = Release|Any CPU
{F6F58D61-D0CB-486F-BA33-884F2589F5C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6F58D61-D0CB-486F-BA33-884F2589F5C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6F58D61-D0CB-486F-BA33-884F2589F5C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6F58D61-D0CB-486F-BA33-884F2589F5C9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB9A97F9-4A2B-4BE1-8115-202C82F7A00F}
EndGlobalSection
EndGlobal
38 changes: 38 additions & 0 deletions Test2.1/Test2.1/BubbleSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test2._1
{
/// <summary>
/// класс с сортировкой пызырьком
/// </summary>
public static class BubbleSort
{
/// <summary>
/// сортировка пузырьком
/// </summary>
/// <typeparam name="T">тип класса</typeparam>
/// <param name="list">лист значений</param>
/// <param name="compare">компаратор</param>
public static void Sort<T>(List<T> list, Comparer<T> compare)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше было принимать по интерфейсу, IComparer

{
var lenght = list.Count;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

length

for (var i = 0; i < lenght; i++)
{
for (var j = lenght - 1; j > i; j--)
{
if (compare.Compare(list[j - 1], list[j]) >= 0)
{
//Swap(ref list[j], list[j + 1]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Закомментированный код не нужен

var helper = list[j - 1];
list[j - 1] = list[j];
list[j] = helper;
}
}
}
}
}
}
20 changes: 20 additions & 0 deletions Test2.1/Test2.1/CompareIntInDescendingOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test2._1
{
/// <summary>
/// сравнивает int, обратное обычное Compare
/// </summary>
public class CompareIntInDescendingOrder : Comparer<int>
{
public override int Compare(int value1, int value2)
{
return value1 <= value2 ? 1 : -1 ;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут и в аналогичном месте ниже стоило использовать =>

}
}
19 changes: 19 additions & 0 deletions Test2.1/Test2.1/CompareStringInDescendingOrder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test2._1
{
/// <summary>
/// сравнивает string, обратное обычное Compare
/// </summary>
public class CompareStringInDescendingOrder : Comparer<string>
{
public override int Compare(string value1, string value2)
{
return value2.CompareTo(value1);
}
}
}
18 changes: 18 additions & 0 deletions Test2.1/Test2.1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;

namespace Test2._1
{
class Program
{
static void Main(string[] args)
{
var list = new List<string>() { "abc", "aa", "bb", "zv", "fe", "qwe", "123" };
BubbleSort.Sort(list, new CompareStringInDescendingOrder());
for (int i = 0; i < list.Count; ++i)
{
Console.WriteLine(list[i]);
}
}
}
}
9 changes: 9 additions & 0 deletions Test2.1/Test2.1/Test2.1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>Test2._1</RootNamespace>
</PropertyGroup>

</Project>