-
Notifications
You must be signed in to change notification settings - Fork 0
Test with BubleSort #16
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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]); | ||
| } | ||
| } | ||
|
|
||
| [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]); | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тестов маловато. Стоило проверить на пустом списке, на списке, где все элементы одинаковы, на null-ы в параметрах. Задача-то простая очень, время было :) |
||
| } | ||
| } | ||
| 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> |
| 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 |
| 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) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лучше было принимать по интерфейсу, IComparer |
||
| { | ||
| var lenght = list.Count; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 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 ; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут и в аналогичном месте ниже стоило использовать => |
||
| } | ||
| } | ||
| 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); | ||
| } | ||
| } | ||
| } |
| 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]); | ||
| } | ||
| } | ||
| } | ||
| } |
| 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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Наоборот, первый параметр --- что ожидали, второй --- что получили