From d365e9ad71835e1d90c4047ec4c3dfb05449bf84 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 13 May 2024 00:38:21 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D1=8C=D1=82?= =?UTF-8?q?=D0=B5=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lab_12_1.sln | 37 +++ Lab_12_1/ClassDiagram1.cd | 58 +++++ Lab_12_1/Lab_12_1.csproj | 14 ++ Lab_12_1/MyList.cs | 234 ++++++++++++++++++ Lab_12_1/Point.cs | 40 +++ Lab_12_1/Program.cs | 115 +++++++++ TestProject1/TestProject1.csproj | 23 ++ TestProject1/UnitTest1.cs | 11 + TestProject322/GlobalUsings.cs | 1 + TestProject322/TestProject322.csproj | 29 +++ TestProject322/UnitTest1.cs | 352 +++++++++++++++++++++++++++ 11 files changed, 914 insertions(+) create mode 100644 Lab_12_1.sln create mode 100644 Lab_12_1/ClassDiagram1.cd create mode 100644 Lab_12_1/Lab_12_1.csproj create mode 100644 Lab_12_1/MyList.cs create mode 100644 Lab_12_1/Point.cs create mode 100644 Lab_12_1/Program.cs create mode 100644 TestProject1/TestProject1.csproj create mode 100644 TestProject1/UnitTest1.cs create mode 100644 TestProject322/GlobalUsings.cs create mode 100644 TestProject322/TestProject322.csproj create mode 100644 TestProject322/UnitTest1.cs diff --git a/Lab_12_1.sln b/Lab_12_1.sln new file mode 100644 index 0000000..915a92c --- /dev/null +++ b/Lab_12_1.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lab_12_1", "Lab_12_1\Lab_12_1.csproj", "{8653E681-31C0-4537-9309-CDFCA13C6D99}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject322", "TestProject322\TestProject322.csproj", "{97069E5A-D43E-4E79-A5D0-7660CF7C944D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary", "..\Labb_10\MusicalInstrument\ClassLibrary.csproj", "{073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8653E681-31C0-4537-9309-CDFCA13C6D99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8653E681-31C0-4537-9309-CDFCA13C6D99}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8653E681-31C0-4537-9309-CDFCA13C6D99}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8653E681-31C0-4537-9309-CDFCA13C6D99}.Release|Any CPU.Build.0 = Release|Any CPU + {97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97069E5A-D43E-4E79-A5D0-7660CF7C944D}.Release|Any CPU.Build.0 = Release|Any CPU + {073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {073A6CA5-DA0F-404B-8C02-4CE78ABDF0A6}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EBDF0207-E7DE-437A-9E0A-9816E4564E43} + EndGlobalSection +EndGlobal diff --git a/Lab_12_1/ClassDiagram1.cd b/Lab_12_1/ClassDiagram1.cd new file mode 100644 index 0000000..56af169 --- /dev/null +++ b/Lab_12_1/ClassDiagram1.cd @@ -0,0 +1,58 @@ + + + + + + ACABAAACAAAABAAABAAAAgQEAAAAEAAUBAEAAAAQAAA= + MyList.cs + + + + + + AgAAAAAAAAAAAAAEAAAAAAAAAAAAAJAAEAAAAAAAAAA= + Point.cs + + + + + + AAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAA= + Program.cs + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lab_12_1/Lab_12_1.csproj b/Lab_12_1/Lab_12_1.csproj new file mode 100644 index 0000000..65a5ff7 --- /dev/null +++ b/Lab_12_1/Lab_12_1.csproj @@ -0,0 +1,14 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + diff --git a/Lab_12_1/MyList.cs b/Lab_12_1/MyList.cs new file mode 100644 index 0000000..ea93bc7 --- /dev/null +++ b/Lab_12_1/MyList.cs @@ -0,0 +1,234 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.Contracts; +using System.Drawing; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Runtime.Serialization.Json; +using System.Security; +using System.Text; +using System.Threading.Tasks; +using ClassLibrary; +using static System.Net.Mime.MediaTypeNames; +namespace Lab_12_1 +{ + public class MyList where T: IInit, ICloneable, new() + { + public Point? beg = null; + public Point? end = null; + + int count = 0; + + public int Count => count; // свойство для чтения + + public Point MakeRandomData() // случайный элемент типа Т + { + T data = new T(); + data.RandomInit(); + return new Point(data); + } + + public T MakeRandomItem() // случайное информационное поле + { + T data = new T(); + data.RandomInit(); + return data; + } + + public void AddToBegin(T item) // добавление в начало + { + T newData = (T)item.Clone(); //глубокое копирование + Point newItem = new Point(newData); + count++; + if (beg != null) + { + beg.Pred = newItem; + newItem.Next = beg; + beg = newItem; + } + else + { + beg = newItem; + end = beg; + } + } + + public void AddToEnd(T item) //добавление в конец + { + T newData = (T)item.Clone(); //глубокое копирование + Point newItem = new Point(newData); + count++; + if (end != null) + { + end.Next = newItem; + newItem.Pred = end; + end = newItem; + } + else + { + beg = newItem; + end = beg; + } + } + + public MyList() { } // конструктор без параметров + + public MyList(int size) // конструктор с параметром 'размер' + { + if (size <= 0) throw new Exception("size less zero"); + beg = MakeRandomData(); + end = beg; + for (int i = 1; i < size; i++) + { + T newItem = MakeRandomItem(); + AddToEnd(newItem); + } + } + + public MyList(T[] collection) // способ задать несколько элементов в виде массива + { + if (collection == null) throw new Exception("empty collection: null"); + if (collection.Length == 0) throw new Exception("empty collection"); + T newData = (T)collection[0].Clone(); + beg = new Point(newData); + end = beg; + for (int i = 1; i < collection.Length; i++) + { + AddToEnd(collection[i]); + } + } + + public void PrintList() // печать списка + { + if (count == 0) Console.WriteLine("this list is empty"); + Point? current = beg; + for (int i = 0; current != null; i++) + { + Console.WriteLine(current); + current = current.Next; + } + } + + public Point? FindItem(T item) //поиск элемента + { + Point? current = beg; + while (current != null) + { + if (current.Data == null) + { + throw new Exception("Data is null"); + } + if (current.Data.Equals(item)) + { + return current; + } + current = current.Next; + } + return null; + } + + public bool RemoveItem(T item) // удаление элемента + { + if (beg == null) throw new Exception("the empty list"); + Point? pos = FindItem(item); + if (pos == null) return false; + count--; + // один элемент + if (beg == end) + { + beg = end = null; + return true; + } + // первый элемент + if (pos.Pred == null) + { + beg = beg?.Next; + beg.Pred = null; + return true; + } + // последний элемент + if (pos.Next == null) + { + end = end.Pred; + end.Next = null; + return true; + } + // для остальных случаев + Point next = pos.Next; + Point pred = pos.Pred; + pos.Next.Pred = pred; + pos.Pred.Next = next; + return true; + } + + public void RemoveItem2(T item) // Удаление элемента с полем и всех последующих + { + if (beg == null) throw new Exception("the empty list"); + Point? tek = beg; + while (tek != null) + { + if (tek.Data != null && tek.Data.Equals(item)) + { + if (tek.Next != null) tek.Next.Pred = null; // Удаление текущего элемента и всех последующих + end = tek.Pred; + end.Next = null; + count--; + break; + } + tek = tek.Next; // Переходим к следующему элементу + } + } + + public MyList CloneList() // глубокое копирование + { + MyList clone = new(); + if (beg == null) return clone; + Point? current = beg; + while (current != null) + { + clone.AddToEnd(current.Data); + current = current.Next; + } + return clone; + } + + public void ClearList() // удалить список из памяти + { + Point? current = beg; + while (current != null) + { + current.Pred = null; + current = current.Next; + } + beg = null; + end = null; + count = 0; + } + + public void AddByPlace() // добавить случайные элементы на места нечётных элементов + { + if (beg == null) throw new Exception("Список пуст."); + Point? current = beg; + int index = 1; + while (current != null) + { + if (index % 2 != 0) + { + // Создаем новый элемент + T newData = new(); + newData.RandomInit(); + Point newPoint = new(newData); + // Добавляем новый элемент после текущего + newPoint.Next = current.Next; + if (current.Next != null) current.Next.Pred = newPoint; + current.Next = newPoint; + newPoint.Pred = current; + count++; + } + // Переходим к следующему элементу + current = current.Next; + index++; + } + } + } +} \ No newline at end of file diff --git a/Lab_12_1/Point.cs b/Lab_12_1/Point.cs new file mode 100644 index 0000000..b354780 --- /dev/null +++ b/Lab_12_1/Point.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata; +using System.Text; +using System.Threading.Tasks; + +namespace Lab_12_1 +{ + public class Point + { + public T? Data { get; set; } + public Point? Next { get; set; } + public Point? Pred { get; set; } + + public Point() + { + this.Data = default(T); + this.Pred = null; + this.Next = null; + } + + public Point(T data) + { + this.Data = data; + this.Pred = null; + this.Next = null; + } + + public override string ToString() + { + return Data == null ? "": Data.ToString(); + } + + public override int GetHashCode() + { + return Data == null ? 0: Data.GetHashCode(); + } + } +} diff --git a/Lab_12_1/Program.cs b/Lab_12_1/Program.cs new file mode 100644 index 0000000..807a000 --- /dev/null +++ b/Lab_12_1/Program.cs @@ -0,0 +1,115 @@ +using System; +using System.Linq.Expressions; +using System.Net.NetworkInformation; +using System.Runtime.Intrinsics.X86; +using System.Security.AccessControl; +using ClassLibrary; +namespace Lab_12_1 +{ + internal class Program + { + static void Main(string[] args) + { + MyList list = new MyList(); + MyList newList = new MyList(); + int answer = 1; + while (answer != 11) + { + try + { + Commands(); + answer = int.Parse(Console.ReadLine()); + switch (answer) + { + case 1: + Console.WriteLine("Введите размер коллекции:"); + int size = int.Parse(Console.ReadLine()); + list = new MyList(size); + Console.WriteLine("Коллекция создана."); + break; + + case 2: + list.PrintList(); + break; + + case 3: + MusicalInstrument muz1 = new MusicalInstrument(); + muz1.RandomInit(); + list.AddToBegin(muz1); + Console.WriteLine("Элемент добавлен в начало."); + break; + + case 4: + MusicalInstrument muz2 = new MusicalInstrument(); + muz2.RandomInit(); + list.AddToEnd(muz2); + Console.WriteLine("Элемент добавлен в конец."); + break; + + case 5: + MusicalInstrument muz3 = new MusicalInstrument(); + muz3.Init(); + if (!list.RemoveItem(muz3)) Console.WriteLine("Элемент не найден."); + else Console.WriteLine("Элемент удалён."); + break; + + case 6: + list.AddByPlace(); + break; + + case 7: + MusicalInstrument muzQ = new MusicalInstrument(); + muzQ.Init(); + list.RemoveItem2(muzQ); + break; + + case 8: + newList = list.CloneList(); + Console.WriteLine("Список скопирован."); + break; + + case 9: + newList.PrintList(); + break; + + case 10: + list.ClearList(); + Console.WriteLine("Список удалён из памяти."); + break; + + case 11: + Console.WriteLine("Change da world. My final massege. Goodbye."); + break; + + default: + Console.WriteLine(); + break; + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + } + } + + private static void Commands() + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Меню.\n" + + "----------------------------------------------------------------------------\n" + + "1. Создать список.\n" + + "2. Распечатать список.\n" + + "3. Добавить элемент в начало списка. \n" + + "4. Добавить элемент в конец списка. \n" + + "5. Удалить элемент в списке.\n" + + "6. Добавить в список новые элементы на нечётные позиции. \n" + + "7. Удалить все элементы, начиная с элемента с заданным информационным полем.\n" + + "8. Скопировать список.\n" + + "9. Распечатать скопированный список. \n" + + "10. Удвлить список из памяти.\n" + + "11. Завершение работы.\n" + + "----------------------------------------------------------------------------\n"); + } + } +} \ No newline at end of file diff --git a/TestProject1/TestProject1.csproj b/TestProject1/TestProject1.csproj new file mode 100644 index 0000000..517a899 --- /dev/null +++ b/TestProject1/TestProject1.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + diff --git a/TestProject1/UnitTest1.cs b/TestProject1/UnitTest1.cs new file mode 100644 index 0000000..91d66c4 --- /dev/null +++ b/TestProject1/UnitTest1.cs @@ -0,0 +1,11 @@ +namespace TestProject1 +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} \ No newline at end of file diff --git a/TestProject322/GlobalUsings.cs b/TestProject322/GlobalUsings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/TestProject322/GlobalUsings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/TestProject322/TestProject322.csproj b/TestProject322/TestProject322.csproj new file mode 100644 index 0000000..68e3614 --- /dev/null +++ b/TestProject322/TestProject322.csproj @@ -0,0 +1,29 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + ..\..\Labb_10\MusicalInstrument\bin\Debug\net7.0\ClassLibrary.dll + + + + diff --git a/TestProject322/UnitTest1.cs b/TestProject322/UnitTest1.cs new file mode 100644 index 0000000..1338a72 --- /dev/null +++ b/TestProject322/UnitTest1.cs @@ -0,0 +1,352 @@ +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Runtime.Intrinsics.X86; +using ClassLibrary; +using Lab_12_1; + +namespace TestProject1 +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethodCreateMyList() + { + MyList muz = new MyList(5); + Assert.AreEqual(4, muz.Count); + } + [TestMethod] + public void TestMethodToString1() + { + string test = ""; + var mmm = new Point(test); + Assert.AreEqual(test, mmm.ToString()); + } + [TestMethod] + public void TestMethodToString2() + { + int test = 12; + var mmm = new Point(test); + string test2 = "12"; + Assert.AreEqual(test2, mmm.ToString()); + } + [TestMethod] + public void TestMethodGetHashCode1() + { + int test = 99; + var mmm = new Point(test); + int hashCode = mmm.GetHashCode(); + Assert.AreEqual(test.GetHashCode(), hashCode); + } + [TestMethod] + public void TestMethodGetHashCode2() + { + int test = 17; + var mmm = new Point(test); + int hashCode = mmm.GetHashCode(); + Assert.AreEqual(test.GetHashCode(), hashCode); + } + [TestMethod] + public void TestMethodAddToBeginForEmptyList1() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(muz, myList.beg.Data); + } + [TestMethod] + public void TestMethodAddToBeginForEmptyList2() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(muz, myList.end.Data); + } + [TestMethod] + public void TestMethodAddToBeginForEmptyList3() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(muz, myList.FindItem(muz).Data); + } + [TestMethod] + public void TestMethodAddToEndForEmptyList1() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.AreEqual(muz, myList.beg.Data); + } + [TestMethod] + public void TestMethodAddToEndForEmptyList2() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.AreEqual(muz, myList.end.Data); + } + [TestMethod] + public void TestMethodAddToEndForEmptyList3() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.AreEqual(muz, myList.FindItem(muz).Data); + } + [TestMethod] + public void TestMethodAddToBeginForNotEmptyList1() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(muz, myList.beg.Data); + } + [TestMethod] + public void TestMethodAddToBeginForNotEmptyList2() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(muz, myList.FindItem(muz).Data); + } + [TestMethod] + public void TestMethodAddToEndForNotEmptyList1() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.AreEqual(muz, myList.end.Data); + } + [TestMethod] + public void TestMethodAddToEndForNotEmptyList2() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.AreEqual(muz, myList.FindItem(muz).Data); + } + [TestMethod] + public void TestMethodFindItemByTitle() + { + MusicalInstrument mz = new MusicalInstrument(); + mz.RandomInit(); + MyList myList = new MyList(5); + myList.AddToBegin(mz); + Assert.AreEqual(5, myList.Count); + } + [TestMethod] + public void TestMethodFindItemFromBeguin() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument(); + myList.AddToBegin(muz); + Assert.IsNotNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodFindItemFromEnd() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument(); + myList.AddToEnd(muz); + Assert.IsNotNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodFindItemInEmptyList() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument(); + Assert.IsNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodFindItemNotExist() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + Assert.IsNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemInEmptyList() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument(); + Assert.ThrowsException(() => { myList.RemoveItem(muz); }); + } + [TestMethod] + public void TestMethodRemoveItemNotExist1() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + Assert.AreEqual(false, myList.RemoveItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemNotExist2() + { + MyList myList = new MyList(5); + MusicalInstrument muz = new MusicalInstrument("", 10); + Assert.IsNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemWhereOneElemInList1() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(true, myList.RemoveItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemFirst1() + { + MyList myList = new MyList(2); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.AreEqual(true, myList.RemoveItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemFirst2() + { + MyList myList = new MyList(2); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToBegin(muz); + Assert.IsNotNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemLast1() + { + MyList myList = new MyList(2); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.AreEqual(true, myList.RemoveItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemLast2() + { + MyList myList = new MyList(2); + MusicalInstrument muz = new MusicalInstrument("", 10); + myList.AddToEnd(muz); + Assert.IsNotNull(myList.FindItem(muz)); + } + [TestMethod] + public void TestMethodRemoveItemClassic1() + { + MyList myList = new MyList(5); + MusicalInstrument muz1 = new MusicalInstrument("", 10); + MusicalInstrument muz2 = new MusicalInstrument("", 50); + myList.AddToBegin(muz1); + myList.AddToBegin(muz2); + Assert.AreEqual(true, myList.RemoveItem(muz1)); + } + [TestMethod] + public void TestMethodRemoveItemClassic2() + { + MyList myList = new MyList(2); + MusicalInstrument muz1 = new MusicalInstrument("", 10); + MusicalInstrument muz2 = new MusicalInstrument("", 50); + myList.AddToBegin(muz1); + myList.AddToBegin(muz2); + Assert.IsNotNull(myList.FindItem(muz1)); + } + [TestMethod] + public void TestMethodCloneList1() + { + MyList myList = new MyList(5); + MyList myListClone = myList.CloneList(); + Assert.IsNotNull(myListClone); + } + [TestMethod] + public void TestMethodCloneList2() + { + MyList myList = new MyList(5); + MyList myListClone = myList.CloneList(); + Assert.AreEqual(5, myListClone.Count); + } + [TestMethod] + public void TestMethodCloneListEmpty() + { + MyList myList = new MyList(); + MyList myListClone = myList.CloneList(); + int count = myList.Count; + Assert.AreEqual(0, count); + } + [TestMethod] + public void TestMethodRemoveItem21() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + Assert.ThrowsException(() => { myList.RemoveItem2(muz); }); + } + [TestMethod] + public void TestMethodRemoveItem22() + { + MyList myList = new MyList(); + MusicalInstrument muz1 = new MusicalInstrument("", 10); + MusicalInstrument muz2 = new MusicalInstrument("", 15); + MusicalInstrument muz3 = new MusicalInstrument("", 10); + MusicalInstrument muz4 = new MusicalInstrument("", 15); + myList.AddToBegin(muz1); + myList.AddToBegin(muz2); + myList.AddToBegin(muz3); + myList.AddToBegin(muz4); + myList.RemoveItem2(muz2); + Assert.AreNotEqual(true, myList.FindItem(muz1)); + Assert.AreNotEqual(true, myList.FindItem(muz2)); + Assert.AreNotEqual(true, myList.FindItem(muz3)); + Assert.AreEqual(true, myList.FindItem(muz4)); + } + [TestMethod] + public void TestMethodAddByPlace1() + { + MyList myList = new MyList(); + MusicalInstrument muz = new MusicalInstrument("", 10); + Assert.ThrowsException(() => { myList.RemoveItem2(muz); }); + } + [TestMethod] + public void TestMethodAddByPlace() + { + MyList myList = new MyList(); + for (int i = 0; i < 3; i++) + { + myList.AddToBegin(new MusicalInstrument("", 10)); + + } + myList.AddByPlace(); + Point? current = myList.beg; + int cnt = 0; + int error = 0; + while (current != null) + { + if (cnt % 2 != 0) + { + if (current.Data.Title == "") + { + error++; + } + } + else + { + if (current.Data.Title != "") + { + error++; + } + } + cnt++; + current = current.Next; + } + Assert.AreEqual(0, error); + } + [TestMethod] + public void TestMethodClearList() + { + MyList myList = new MyList(5); + myList.ClearList(); + Point? current = myList.beg; + int cnt = 0; + while (current != null) + { + cnt++; + current = current.Next; + } + Assert.AreEqual(0, cnt); + } + } +}