diff --git a/Test2.1/Test2.1.Test/Test.cs b/Test2.1/Test2.1.Test/Test.cs new file mode 100644 index 0000000..676a089 --- /dev/null +++ b/Test2.1/Test2.1.Test/Test.cs @@ -0,0 +1,41 @@ +using NUnit.Framework; +using System.Collections.Generic; + +namespace Test2._1.Test +{ + public class Tests + { + private List listInt; + + private List listString; + + [SetUp] + public void Setup() + { + listInt = new List() { 23 , 11, 13, 43, 12, 4, 32, 1 }; + listString = new List() { "abc", "aa", "bb", "zv", "fe", "qwe", "123" }; + } + + [Test] + public void TestForInt() + { + var listCheck = new List() { 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() { "zv", "qwe", "fe", "bb", "abc", "aa", "123" }; + for (int i = 0; i < listString.Count; ++i) + { + Assert.AreEqual(listString[i], listCheck[i]); + } + } + } +} \ No newline at end of file diff --git a/Test2.1/Test2.1.Test/Test2.1.Test.csproj b/Test2.1/Test2.1.Test/Test2.1.Test.csproj new file mode 100644 index 0000000..45d496e --- /dev/null +++ b/Test2.1/Test2.1.Test/Test2.1.Test.csproj @@ -0,0 +1,20 @@ + + + + net5.0 + Test2._1.Test + + false + + + + + + + + + + + + + diff --git a/Test2.1/Test2.1.sln b/Test2.1/Test2.1.sln new file mode 100644 index 0000000..e793fe1 --- /dev/null +++ b/Test2.1/Test2.1.sln @@ -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 diff --git a/Test2.1/Test2.1/BubbleSort.cs b/Test2.1/Test2.1/BubbleSort.cs new file mode 100644 index 0000000..d5c46dc --- /dev/null +++ b/Test2.1/Test2.1/BubbleSort.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Test2._1 +{ + /// + /// класс с сортировкой пызырьком + /// + public static class BubbleSort + { + /// + /// сортировка пузырьком + /// + /// тип класса + /// лист значений + /// компаратор + public static void Sort(List list, Comparer compare) + { + var lenght = list.Count; + 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]); + var helper = list[j - 1]; + list[j - 1] = list[j]; + list[j] = helper; + } + } + } + } + } +} \ No newline at end of file diff --git a/Test2.1/Test2.1/CompareIntInDescendingOrder.cs b/Test2.1/Test2.1/CompareIntInDescendingOrder.cs new file mode 100644 index 0000000..059446a --- /dev/null +++ b/Test2.1/Test2.1/CompareIntInDescendingOrder.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Test2._1 +{ + /// + /// сравнивает int, обратное обычное Compare + /// + public class CompareIntInDescendingOrder : Comparer + { + public override int Compare(int value1, int value2) + { + return value1 <= value2 ? 1 : -1 ; + } + } +} diff --git a/Test2.1/Test2.1/CompareStringInDescendingOrder.cs b/Test2.1/Test2.1/CompareStringInDescendingOrder.cs new file mode 100644 index 0000000..8e823a4 --- /dev/null +++ b/Test2.1/Test2.1/CompareStringInDescendingOrder.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Test2._1 +{ + /// + /// сравнивает string, обратное обычное Compare + /// + public class CompareStringInDescendingOrder : Comparer + { + public override int Compare(string value1, string value2) + { + return value2.CompareTo(value1); + } + } +} diff --git a/Test2.1/Test2.1/Program.cs b/Test2.1/Test2.1/Program.cs new file mode 100644 index 0000000..02e9feb --- /dev/null +++ b/Test2.1/Test2.1/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; + +namespace Test2._1 +{ + class Program + { + static void Main(string[] args) + { + var list = new List() { "abc", "aa", "bb", "zv", "fe", "qwe", "123" }; + BubbleSort.Sort(list, new CompareStringInDescendingOrder()); + for (int i = 0; i < list.Count; ++i) + { + Console.WriteLine(list[i]); + } + } + } +} diff --git a/Test2.1/Test2.1/Test2.1.csproj b/Test2.1/Test2.1/Test2.1.csproj new file mode 100644 index 0000000..2598546 --- /dev/null +++ b/Test2.1/Test2.1/Test2.1.csproj @@ -0,0 +1,9 @@ + + + + Exe + net5.0 + Test2._1 + + +