public void AddItemByValue() { testListAsc.Add(12); Assert.AreEqual(1, testListAsc.Count()); testListAsc.Add(2); Assert.AreEqual(2, testListAsc.Count()); testListAsc.Add(0); Assert.AreEqual(3, testListAsc.Count()); testListAsc.Add(-6); Assert.AreEqual(4, testListAsc.Count()); testListAsc.Add(50); Assert.AreEqual(5, testListAsc.Count()); testListAsc.Add(-64); Assert.AreEqual(6, testListAsc.Count()); testListAsc.Add(-2); Assert.AreEqual(7, testListAsc.Count()); testListAsc.Add(0); Assert.AreEqual(8, testListAsc.Count()); testListAsc.Add(500); Assert.AreEqual(9, testListAsc.Count()); testListAsc.Add(500); Assert.AreEqual(10, testListAsc.Count()); testListAsc.Add(51); Assert.AreEqual(11, testListAsc.Count()); testListAsc.Add(-2); Assert.AreEqual(12, testListAsc.Count()); testListAsc.Add(5000); Assert.AreEqual(13, testListAsc.Count()); testListAsc.Add(5000); Assert.AreEqual(14, testListAsc.Count()); testListAsc.Add(-6422); Assert.AreEqual(15, testListAsc.Count()); testListDesc.Add(0); Assert.AreEqual(1, testListDesc.Count()); testListDesc.Add(12); Assert.AreEqual(2, testListDesc.Count()); testListDesc.Add(55); Assert.AreEqual(3, testListDesc.Count()); testListDesc.Add(-2113); Assert.AreEqual(4, testListDesc.Count()); testListDesc.Add(30); Assert.AreEqual(5, testListDesc.Count()); testListDesc.Add(0); Assert.AreEqual(6, testListDesc.Count()); testListDesc.Add(-1050); Assert.AreEqual(7, testListDesc.Count()); testListDesc.Add(50); Assert.AreEqual(8, testListDesc.Count()); testListDesc.Add(50); Assert.AreEqual(9, testListDesc.Count()); testListDesc.Add(50); Assert.AreEqual(10, testListDesc.Count()); testListDesc.Add(100); Assert.AreEqual(11, testListDesc.Count()); testListDesc.Add(230); Assert.AreEqual(12, testListDesc.Count()); testListDesc.Add(41); Assert.AreEqual(13, testListDesc.Count()); testListDesc.Add(-1234); Assert.AreEqual(14, testListDesc.Count()); testListDesc.Add(1200); Assert.AreEqual(15, testListDesc.Count()); }
static void TestAddSortedList(bool asc) { Console.WriteLine("test ordered list asc = " + asc); OrderedList <int> orderedList = new OrderedList <int>(asc); Console.WriteLine("test add "); Console.WriteLine("head before add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail before add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); Console.WriteLine("size before add = " + orderedList.Count()); for (int i = 1, val = 1; i <= 15; i++, val += 10) { orderedList.Add(val); Console.Write(val + " "); } Console.WriteLine(); ShowListElements(orderedList); Console.WriteLine(); ShowListElementsReverse(orderedList); Console.WriteLine("size after add = " + orderedList.Count()); Console.WriteLine("head after add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail after add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); Console.WriteLine(); Console.WriteLine("test delete 91"); Console.WriteLine("size before add = " + orderedList.Count()); Console.WriteLine("head before add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail before add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); orderedList.Delete(91); ShowListElements(orderedList); Console.WriteLine(); ShowListElementsReverse(orderedList); Console.WriteLine(); Console.WriteLine("size after add = " + orderedList.Count()); Console.WriteLine("head after add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail after add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); Console.WriteLine(); Console.WriteLine("test delete 1"); Console.WriteLine("size before add = " + orderedList.Count()); Console.WriteLine("head before add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail before add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); orderedList.Delete(1); ShowListElements(orderedList); Console.WriteLine(); ShowListElementsReverse(orderedList); Console.WriteLine(); Console.WriteLine("size after add = " + orderedList.Count()); Console.WriteLine("head after add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail after add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); Console.WriteLine(); Console.WriteLine("test delete 141"); Console.WriteLine("size before add = " + orderedList.Count()); Console.WriteLine("head before add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail before add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); orderedList.Delete(141); ShowListElements(orderedList); Console.WriteLine(); ShowListElementsReverse(orderedList); Console.WriteLine(); Console.WriteLine("size after add = " + orderedList.Count()); Console.WriteLine("head after add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail after add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); Console.WriteLine(); Console.WriteLine("test find 71"); var result = orderedList.Find(71); Console.WriteLine(result.value); Console.WriteLine(); Console.WriteLine("test find 131"); result = orderedList.Find(131); Console.WriteLine(result.value); Console.WriteLine(); Console.WriteLine("test find 11"); result = orderedList.Find(11); Console.WriteLine(result.value); Console.WriteLine(); Console.WriteLine("test find 1000"); result = orderedList.Find(1000); Console.WriteLine(result == null ? "null" : result.value.ToString()); Console.WriteLine(); Console.WriteLine("test clear"); orderedList.Clear(asc); Console.WriteLine("size after add = " + orderedList.Count()); Console.WriteLine("head after add = " + (orderedList.head == null ? "null" : orderedList.head.value.ToString())); Console.WriteLine("tail after add = " + (orderedList.tail == null ? "null" : orderedList.tail.value.ToString())); Console.WriteLine(new string('=', 50)); }