public void ConstructListSucceeds() { IList <int> list = new UnsortedList <int>(10); Assert.IsNotNull(list); Assert.IsTrue(list.Length() == 0); }
public int SortAsc() { var count = UnsortedList.Count; float[] usTab = UnsortedList.ToArray(); int ca = 0; for (int i = 0; i < count; i++) { int lowestIndex = i; for (int j = i + 1; j < count; j++) { if (usTab[j] < usTab[lowestIndex]) { lowestIndex = j; } ca++; } float temp = usTab[i]; usTab[i] = usTab[lowestIndex]; usTab[lowestIndex] = temp; } var temporaryList = new List <float>(); for (int i = 0; i < count; i++) { temporaryList.Add(usTab[i]); } SortedList = temporaryList; return(ca); }
public void SortListContainersTest_SortAllContainers_ReturnEqual() { //Arrange UnsortedList unsortedlist = new UnsortedList(); Container normal10 = new Container(ContainerType.Normal, 10); Container normal15 = new Container(ContainerType.Normal, 15); Container valuable15 = new Container(ContainerType.Valuable, 15); Container valuable25 = new Container(ContainerType.Valuable, 25); Container coolable20 = new Container(ContainerType.Coolable, 20); Container coolable25 = new Container(ContainerType.Coolable, 25); List <Container> containers = new List <Container>(); List <Container> expected = new List <Container>(); expected.Add(coolable25); expected.Add(coolable20); expected.Add(normal15); expected.Add(normal10); expected.Add(valuable25); expected.Add(valuable15); containers.Add(valuable25); containers.Add(coolable20); containers.Add(coolable25); containers.Add(normal15); containers.Add(valuable15); containers.Add(normal10); //Act unsortedlist.AddContainers(containers); unsortedlist.SortListContainers(); //Assert CollectionAssert.AreEqual(expected, unsortedlist.SortedContainerList); }
// funkcja tworzaca liste oraz inicjalizujaca funkcje testowa / static TimeSpan TestOfUnsortedList(int A, int B, int M, int N) { // zwraca czas wykonania testu UnsortedList<int> l1 = new UnsortedList<int>(); return l1.Test(A, B, M, N); }
public void AddItemSucceeds() { IList <int> list = new UnsortedList <int>(10); list.AddItem(16); Assert.IsTrue(list.Contains(16)); }
public void AddItemFailsWithDuplicateItem() { IList <int> list = new UnsortedList <int>(10); list.AddItem(16); Assert.ThrowsException <InvalidOperationException>(() => list.AddItem(16)); }
public int SortAscWrite() { int count = UnsortedList.Count; float[] usTab = UnsortedList.ToArray(); var temporaryList = new List <float>(); int ca = 0, cb = 0; Console.WriteLine("Bubble sort started work on following set:"); ObjSort.DisplayList(this.UnsortedList); for (int i = 0; i < count - 1; i++) { bool changed = false; for (int j = 0; j < count - i - 1; j++) { if (usTab[j] > usTab[j + 1]) { changed = true; float temp = usTab[j]; usTab[j] = usTab[j + 1]; usTab[j + 1] = temp; // wyświetlanie for (int k = 0; k < usTab.Length; k++) { if (k == j || k == j + 1) { Console.ForegroundColor = ConsoleColor.Green; Console.Write(" |" + usTab[k]); Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" |" + usTab[k]); } } Console.WriteLine(); ca++; } else { cb++; } } if (!changed) { break; } } for (int i = 0; i < count; i++) { temporaryList.Add(usTab[i]); } SortedList = temporaryList; Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca} + {cb} jeśli liczyć te bez zamiany elementów"); return(ca + cb); }
public void AddItemFailsWithFullList() { IList <int> list = new UnsortedList <int>(3); list.AddItem(3); list.AddItem(16); list.AddItem(2); Assert.ThrowsException <InvalidOperationException>(() => list.AddItem(23)); }
public void ListIsFullFails() { IList <int> list = new UnsortedList <int>(10); list.AddItem(16); list.AddItem(3); list.AddItem(11); Assert.IsFalse(list.IsFull()); }
public void ListIsFullSucceeds() { IList <int> list = new UnsortedList <int>(3); list.AddItem(16); list.AddItem(3); list.AddItem(11); Assert.IsTrue(list.IsFull()); }
public void RemoveItemFailsWithMissingItem() { IList <int> list = new UnsortedList <int>(5); list.AddItem(16); list.AddItem(3); list.AddItem(11); list.AddItem(4); list.AddItem(25); Assert.ThrowsException <InvalidOperationException>(() => list.RemoveItem(32)); }
public void EmptyListSucceeds() { IList <int> list = new UnsortedList <int>(10); list.AddItem(16); Assert.IsTrue(list.Contains(16)); list.Empty(); Assert.IsFalse(list.Contains(16)); }
public void GetNextItemSucceeds() { IList <int> list = new UnsortedList <int>(10); list.AddItem(16); list.AddItem(3); list.AddItem(11); Assert.IsTrue(list.GetNextItem() == 16); Assert.IsTrue(list.GetNextItem() == 3); Assert.IsTrue(list.GetNextItem() == 11); }
public int SortAscWrite() { var count = UnsortedList.Count; float[] usTab = UnsortedList.ToArray(); int ca = 0; Console.WriteLine("Select sort started work on following set:"); ObjSort.DisplayList(this.UnsortedList); for (int i = 0; i < count; i++) { int lowestIndex = i; for (int j = i + 1; j < count; j++) { if (usTab[j] < usTab[lowestIndex]) { lowestIndex = j; } ca++; } float temp = usTab[i]; usTab[i] = usTab[lowestIndex]; usTab[lowestIndex] = temp; // wyświetlanie for (int k = 0; k < usTab.Length; k++) { if (k == i || k == lowestIndex) { Console.ForegroundColor = ConsoleColor.Green; Console.Write(" |" + usTab[k]); Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" |" + usTab[k]); } } Console.WriteLine(); } var temporaryList = new List <float>(); for (int i = 0; i < count; i++) { temporaryList.Add(usTab[i]); } SortedList = temporaryList; Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca}"); return(ca); }
public void GetWeightTest_TotalWeight_AreEqual() { //Arrange UnsortedList unsortedlist = new UnsortedList(); List <Container> containerlist = new List <Container>(); Container valuable15 = new Container(ContainerType.Valuable, 15); int expected = 45; //Act containerlist.Add(valuable15); containerlist.Add(valuable15); containerlist.Add(valuable15); unsortedlist.AddContainers(containerlist); int result = unsortedlist.GetWeight(); //Assert Assert.AreEqual(expected, result); }
public int SortAsc() { int count = UnsortedList.Count; float[] usTab = UnsortedList.ToArray(); var temporaryList = new List <float>(); ca = 0; Quick(usTab, 0, count - 1); for (int i = 0; i < count; i++) { temporaryList.Add(usTab[i]); } SortedList = temporaryList; return(ca); }
public int SortAscWrite() { int n = UnsortedList.Count; usTab = UnsortedList.ToArray(); int ca = 0; Console.WriteLine("Heap sort started work on following set:"); ObjSort.DisplayList(this.UnsortedList); for (int i = n / 2 - 1; i >= 0; i--) { ca += heapifyWrite(n, i); } for (int i = n - 1; i >= 0; i--) { float temp = usTab[0]; usTab[0] = usTab[i]; usTab[i] = temp; // wyświetlanie for (int k = 0; k < usTab.Length; k++) { if (k == i || k == 0) { Console.ForegroundColor = ConsoleColor.Green; Console.Write(" |" + usTab[k]); Console.ForegroundColor = ConsoleColor.White; } else { Console.Write(" |" + usTab[k]); } } Console.WriteLine(); ca++; ca += heapifyWrite(i, 0); } Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca}"); LoadSorted(usTab); return(ca); }
public void RemoveItemSucceeds() { IList <int> list = new UnsortedList <int>(5); list.AddItem(16); list.AddItem(3); list.AddItem(11); list.AddItem(4); list.AddItem(25); Assert.IsTrue(list.Length() == 5); list.RemoveItem(11); Assert.IsTrue(list.Length() == 4); Assert.IsTrue(list.GetNextItem() == 16); Assert.IsTrue(list.GetNextItem() == 3); Assert.IsTrue(list.GetNextItem() == 4); Assert.IsTrue(list.GetNextItem() == 25); }
public int SortAsc() { int count = UnsortedList.Count; float[] usTab = UnsortedList.ToArray(); var temporaryList = new List <float>(); int ca = 0, cb = 0; for (int i = 0; i < count - 1; i++) { bool changed = false; for (int j = 0; j < count - i - 1; j++) { if (usTab[j] > usTab[j + 1]) { changed = true; float temp = usTab[j]; usTab[j] = usTab[j + 1]; usTab[j + 1] = temp; ca++; } else { cb++; } } if (!changed) { break; } } for (int i = 0; i < count; i++) { temporaryList.Add(usTab[i]); } SortedList = temporaryList; //Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca} + {cb} jeśli liczyć te bez zamiany elementów"); return(ca + cb); }
public int SortAsc() { int n = UnsortedList.Count; usTab = UnsortedList.ToArray(); int ca = 0; for (int i = n / 2 - 1; i >= 0; i--) { ca += heapify(n, i); } for (int i = n - 1; i >= 0; i--) { float temp = usTab[0]; usTab[0] = usTab[i]; usTab[i] = temp; ca += heapify(i, 0); } LoadSorted(usTab); return(ca); }
public void SortListContainersTest_Sortcold_ReturnEqual() { //Arrange UnsortedList unsortedlist = new UnsortedList(); Container container10 = new Container(ContainerType.Coolable, 10); Container container15 = new Container(ContainerType.Coolable, 15); Container container20 = new Container(ContainerType.Coolable, 20); List <Container> expected = new List <Container>(); List <Container> containers = new List <Container>(); expected.Add(container20); expected.Add(container15); expected.Add(container10); containers.Add(container15); containers.Add(container10); containers.Add(container20); //Act unsortedlist.AddContainers(containers); unsortedlist.SortListContainers(); //Assert CollectionAssert.AreEqual(expected, unsortedlist.SortedContainerList); }
public void UnsortedListTest() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); UnsortedList<int> l1 = new UnsortedList<int>(); for (int i = 0; i < numberOfInsertedElements; i++) { l1.Add(o[i]); } stopWatch.Stop(); Console.WriteLine("Inserting into Unsorted List time: {0}", stopWatch.Elapsed); stopWatch.Start(); for (int i = 0; i < numberOfDeletedElements; i++) { l1.ReturnMin(); } l1.Add(o[numberOfInsertedElements]); stopWatch.Stop(); Console.WriteLine("Deleting from Unsorted List and inserting 1 elemento time: {0}", stopWatch.Elapsed); }
public int SortAscWrite() { int count = UnsortedList.Count; float[] usTab = UnsortedList.ToArray(); var temporaryList = new List <float>(); ca = 0; Console.WriteLine("Bubble sort started work on following set:"); ObjSort.DisplayList(this.UnsortedList); QuickWrite(usTab, 0, count - 1); for (int i = 0; i < count; i++) { temporaryList.Add(usTab[i]); } SortedList = temporaryList; Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"Sortowanie zakończone, liczba kroków: {ca}"); return(ca); }
public HeapSort(List <float> list) : base(list) { usTab = UnsortedList.ToArray(); }
public HeapSort(string file) : base(file) { usTab = UnsortedList.ToArray(); }