public static void TestFindOrderedListIntDesc() { var list = new OrderedList <int>(false); Assert.AreEqual(0, list.Count(), "TestFindOrderedListIntAsc orderedList size must be 0, but not"); list.Add(4); list.Add(3); list.Add(2); list.Add(1); Assert.AreEqual(4, list.Count(), "TestFindOrderedListIntAsc orderedList size must be 4, but not"); var found = list.Find(3); Assert.AreEqual(3, found.value); Assert.AreEqual(4, found.prev.value); Assert.AreEqual(2, found.next.value); found = list.Find(4); Assert.AreEqual(4, found.value); Assert.AreEqual(3, found.next.value); Assert.IsNull(found.prev); found = list.Find(1); Assert.AreEqual(1, found.value); Assert.AreEqual(2, found.prev.value); Assert.IsNull(found.next); }
public void DeleteTest() { OrderedList <int> orderedListAsc = CreateOrderedList( true, 0, 9, 8, 1, 2, 3, 7, 6, 5, 4); Assert.Equal(10, orderedListAsc.Count()); orderedListAsc.Delete(10); Assert.Equal(10, orderedListAsc.Count()); orderedListAsc.Delete(9); Assert.Equal(9, orderedListAsc.Count()); }
public void TestDeleteStringAsc_3() { OrderedList <string> ord = new OrderedList <string>(true); ord.Add("Fat32"); ord.Add("Fat32"); ord.Add("Fat"); ord.Add("Fat"); Assert.AreEqual(4, ord.Count()); ord.Delete("Fat"); Assert.AreEqual(3, ord.Count()); }
public void Find_in_Empty_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); Assert.IsNull(tList.Find(19)); Assert.IsTrue(tList.Count() == 0); }
public void TestCreateSize() { var stack = new OrderedList <int>(true); Assert.True(stack.Count() == 0); Assert.True(stack.head == null); Assert.True(stack.tail == null); }
public void Delete_from_Empty_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); tList.Delete(42); Assert.IsTrue(tList.Count() == 0); }
public void CountTest() { OrderedList <int> orderedListAsc = CreateOrderedList( true, 0, 9, 8, 1, 2, 3, 7, 6, 5, 4); Assert.Equal(10, orderedListAsc.Count()); }
public static void TestAddOrderedListIntAsc() { var list = new OrderedList <int>(true); Assert.AreEqual(0, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 0, but not"); list.Add(1); Assert.AreEqual(1, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 1, but not"); list.Add(3); Assert.AreEqual(2, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 2, but not"); list.Add(4); Assert.AreEqual(3, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 3, but not"); list.Add(2); Assert.AreEqual(4, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 4, but not"); list.Add(0); Assert.AreEqual(5, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 5, but not"); list.Add(-1); Assert.AreEqual(6, list.Count(), "TestAddOrderedListIntAsc orderedList size must be 6, but not"); var counter = -1; var node = list.head; while (node != null) { Assert.AreEqual(counter, node.value, "Test TestAddOrderedListIntAsc failed. List sequence is not correct"); counter += 1; node = node.next; } Assert.AreEqual(5, counter, "TestAddOrderedListIntAsc counter must be 6, but not"); }
public void Test_Count_WhenNotFound() { var list = new OrderedList <int>(true); list.Add(1); list.Add(2); list.Add(3); var result = list.Count(); Assert.AreEqual(3, result); }
public void TestClearAsc() { var stack = new OrderedList <int>(true); stack.Add(1); stack.Add(3); stack.Add(5); stack.Add(0); stack.Add(2); stack.Add(7); stack.Add(4); stack.Add(4); stack.Clear(true); Assert.True(stack.Count() == 0); stack.Add(1); stack.Add(2); Assert.True(stack.ToString().Equals("1 2")); Assert.True(stack.Count() == 2); }
public void Add_Empty_Asc_List() { OrderedList <int> tList = new OrderedList <int>(true); tList.Add(19); int expectedSize = 1; int actualSize = tList.Count(); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.value == 19); Assert.IsTrue(tList.tail.value == 19); }
public void TestCountAsc_1() { OrderedList <int> ord = new OrderedList <int>(true); ord.Add(3); ord.Add(2); ord.Add(1); Assert.AreEqual(3, ord.Count()); ord.Delete(1); Assert.AreEqual(2, ord.Count()); ord.Delete(2); ord.Delete(3); Assert.AreEqual(0, ord.Count()); ord.Delete(1); Assert.AreEqual(0, ord.Count()); }
public static void TestRemoveOrderedListIntDesc() { var list = new OrderedList <int>(false); Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 0, but not"); list.Add(4); list.Add(3); list.Add(2); list.Add(1); Assert.AreEqual(4, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 4, but not"); var counter = 4; var node = list.head; while (node != null) { Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct"); counter -= 1; node = node.next; } list.Delete(3); Assert.AreEqual(3, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 3, but not"); list.Delete(2); Assert.AreEqual(2, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 2, but not"); counter = 4; node = list.head; while (node != null) { Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct"); counter -= 3; node = node.next; } list.Delete(1); Assert.AreEqual(1, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 1, but not"); counter = 4; node = list.head; while (node != null) { Assert.AreEqual(counter, node.value, "Test TestRemoveOrderedListIntDesc failed. List sequence is not correct"); counter -= 1; node = node.next; } list.Delete(4); Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntDesc orderedList size must be 0, but not"); list.Delete(4); Assert.AreEqual(0, list.Count(), "TestRemoveOrderedListIntAsc orderedList size must be 0, but not"); }
private void CheckCorrectOrder(OrderedList <int> orderedList, bool ascending) { switch (orderedList.Count()) { case 0: Assert.Null(orderedList.head); Assert.Null(orderedList.tail); return; case 1: Assert.Null(orderedList.head.prev); Assert.NotNull(orderedList.head); Assert.Null(orderedList.head.next); Assert.Null(orderedList.tail.prev); Assert.NotNull(orderedList.tail); Assert.Null(orderedList.tail.next); return; } Node <int> node = orderedList.head; if (ascending) { while (node != null) { if (node.next != null) { Assert.True(node.next.value >= node.value); } node = node.next; } } else { while (node != null) { if (node.next != null) { Assert.True(node.next.value <= node.value); } node = node.next; } } }
public void Delete_if_Elem_Is_Not_Exists_in_Asc_List() { OrderedList <int> tList = new OrderedList <int>(true); tList.Add(12); tList.Add(48); tList.Add(35); tList.Add(-101); tList.Delete(42); Node <int> actualFoundValue = tList.Find(42); int expectedSize = 4; int actualSize = tList.Count(); Assert.IsNull(actualFoundValue); Assert.AreEqual(expectedSize, actualSize); }
public void TestAddStringAsc_6() { OrderedList <string> ord = new OrderedList <string>(true); ord.Add(""); ord.Add(""); Assert.AreEqual("", ord.head.value); Assert.AreEqual("", ord.head.next.value); Assert.AreEqual("", ord.tail.value); Assert.AreEqual("", ord.tail.prev.value); ord.Add(" "); Assert.AreEqual(" ", ord.head.next.next.value); Assert.AreEqual("", ord.tail.prev.value); Assert.AreEqual(3, ord.Count()); }
public void Add_if_Less_than_the_Head_Asc_List() { OrderedList <int> tList = new OrderedList <int>(true); tList.Add(2); tList.Add(3); tList.Add(9); tList.Add(0); int expectedSize = 4; int actualSize = tList.Count(); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.value == 0); Assert.IsTrue(tList.head.next.value == 2); Assert.IsTrue(tList.tail.value == 9); }
public void Add_if_More_than_the_Tail_Asc_List() { OrderedList <int> tList = new OrderedList <int>(true); tList.Add(1); tList.Add(2); tList.Add(3); tList.Add(9); int expectedSize = 4; int actualSize = tList.Count(); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.value == 1); Assert.IsTrue(tList.tail.value == 9); Assert.IsTrue(tList.tail.prev.value == 3); }
public void Add_in_between_nodes_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); tList.Add(9); tList.Add(7); tList.Add(8); int expectedSize = 3; int actualSize = tList.Count(); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.value == 9); Assert.IsTrue(tList.head.next.value == 8); Assert.IsTrue(tList.tail.value == 7); Assert.IsTrue(tList.tail.prev.value == 8); }
public void Add_in_between_nodes_Asc_List() { OrderedList <int> tList = new OrderedList <int>(true); tList.Add(1); tList.Add(3); tList.Add(2); int expectedSize = 3; int actualSize = tList.Count(); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.value == 1); Assert.IsTrue(tList.head.next.value == 2); Assert.IsTrue(tList.tail.value == 3); Assert.IsTrue(tList.tail.prev.value == 2); }
public void Add_if_More_than_the_Head_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); tList.Add(5); tList.Add(6); tList.Add(8); tList.Add(19); int expectedSize = 4; int actualSize = tList.Count(); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.value == 19); Assert.IsTrue(tList.tail.value == 5); Assert.IsTrue(tList.head.next.value == 8); }
public void Delete_if_Elem_Is_Not_Exists_in_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); tList.Add(122); tList.Add(7); tList.Add(21); tList.Add(7); tList.Add(0); tList.Delete(42); Node <int> actualFoundValue = tList.Find(42); int expectedSize = 5; int actualSize = tList.Count(); Assert.IsNull(actualFoundValue); Assert.AreEqual(expectedSize, actualSize); }
public void Add_if_Exists_Duplicate_Element_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); tList.Add(10); tList.Add(9); tList.Add(1); tList.Add(5); tList.Add(1); tList.Add(6); tList.Add(2); tList.Add(8); tList.Add(7); tList.Add(4); Assert.IsTrue(tList.Count() == 10); Assert.IsTrue(tList.tail.value == 1); Assert.IsTrue(tList.tail.prev.value == 1); Assert.IsTrue(tList.tail.prev.next.value == 1); Assert.IsTrue(tList.tail.prev.prev.value == 2); }
public void Delete_if_Elem_Is_Exists_in_Desc_List() { OrderedList <int> tList = new OrderedList <int>(false); tList.Add(12); tList.Add(48); tList.Add(35); tList.Add(-101); tList.Delete(12); Node <int> actualFoundValue = tList.Find(12); int expectedSize = 3; int actualSize = tList.Count(); Assert.IsNull(actualFoundValue); Assert.AreEqual(expectedSize, actualSize); Assert.IsTrue(tList.head.next.next.value == -101); Assert.IsTrue(tList.tail.prev.value == 35); }
public void AddTest() { OrderedList <int> orderedListAsc = CreateOrderedList( true, 0, 9, 8, 1, 2, 3, 7, 6, 5, 4); orderedListAsc.Add(101); orderedListAsc.Add(50); orderedListAsc.Add(150); CheckCorrectOrder(orderedListAsc, true); Assert.Equal(13, orderedListAsc.Count()); OrderedList <int> orderedListDesc = CreateOrderedList( false, 9, 8, 1, 2, 3, 7, 6, 5, 4); orderedListDesc.Add(101); orderedListDesc.Add(50); orderedListDesc.Add(150); orderedListDesc.Add(0); CheckCorrectOrder(orderedListDesc, false); Assert.Equal(13, orderedListDesc.Count()); }
public static void TestAddOrderedListStringAsc() { var list = new OrderedList <string>(true); var etalon = new Dictionary <int, string>(); Assert.AreEqual(0, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 0, but not"); list.Add("c"); etalon.Add(1, "c"); Assert.AreEqual(1, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 1, but not"); list.Add("e"); etalon.Add(3, "e"); Assert.AreEqual(2, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 2, but not"); list.Add("f"); etalon.Add(4, "f"); Assert.AreEqual(3, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 3, but not"); list.Add("d"); etalon.Add(2, "d"); Assert.AreEqual(4, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 4, but not"); list.Add("b"); etalon.Add(0, "b"); Assert.AreEqual(5, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 5, but not"); list.Add("a"); etalon.Add(-1, "a"); Assert.AreEqual(6, list.Count(), "TestAddOrderedListStringAsc orderedList size must be 6, but not"); var counter = -1; var node = list.head; while (node != null) { Assert.AreEqual(etalon[counter], node.value, "Test TestAddOrderedListStringAsc failed. List sequence is not correct"); counter += 1; node = node.next; } Assert.AreEqual(5, counter, "TestAddOrderedListStringAsc counter must be 6, but not"); }