public void AddAfterPUT([PexAssumeUnderTest] IList <int> values, int toAddValue) { PexAssume.IsFalse(values.Contains(toAddValue)); DoublyLinkedList <int> dll = new DoublyLinkedList <int>(values); if (values.Count == 0) { dll.AddAfter(dll.Head, toAddValue); PexAssert.IsFalse(true, "InvalidOperationException was expected"); } dll.AddAfter(dll.Head.Next, toAddValue); if (values.Count == 1) { PexAssert.IsFalse(true, "ArgumentNullException was expected"); } PexAssert.AreEqual(toAddValue, dll.Head.Next.Next.Value); PexAssert.AreEqual(values[1], dll.Head.Next.Next.Previous.Value); if (values.Count > 2) { PexAssert.AreEqual(values[2], dll.Head.Next.Next.Next.Value); if (values.Count == 3) { PexAssert.AreEqual(toAddValue, dll.Tail.Previous.Value); } } }
public void AddAfterTest() { var list = new DoublyLinkedList <int>(); var node = list.AddFirst(1); node = list.AddAfter(node, 2); node = list.AddAfter(node, 3); Assert.IsTrue(list.Last.Value == 3, "Incorrectly added node"); }
public void RemoveTest() { var list = new DoublyLinkedList <int>(); var node = list.AddFirst(1); node = list.AddAfter(node, 2); list.AddAfter(node, 3); list.Remove(node); Assert.IsTrue(list.First.Value == 1 && list.Last.Value == 3, "Node deletion is incorrect"); }
public void AddAfter(int oldItem, int item) { for (int i = 1; i <= 5; i++) { doublyLinkedListTest.AddLast(i); } doublyLinkedListTest.AddAfter(oldItem, item); Assert.AreEqual(doublyLinkedListTest.Count(), 6, "invalid count"); Assert.IsTrue(doublyLinkedListTest.Contains(item), "Item doesn't exists."); }
public void ListTestAddAfter(int expectedCount, int[] values) { var list = new DoublyLinkedList <int>(); foreach (var item in values) { if (list.Count > 0) { list.AddAfter(list.Tail, item); } else { list.AddNodeToFront(item); } } Assert.Equal(expectedCount, list.Count); if (expectedCount > 0) { Assert.Equal(list.Head.prev, list.Tail); Assert.Equal(list.Tail.next, list.Head); Assert.NotNull(list.Head); Assert.NotNull(list.Tail); Assert.Equal(values[0], list.Head.data); Assert.Equal(values[values.Length - 1], list.Tail.data); } }
public void AddAfterTheMiddleNodeAndCheckForOrder() { var list = new DoublyLinkedList <int>(); int itemCount = 1000; var middleNode = new DoublyLinkedListNode <int>(0); for (int i = 0; i < itemCount; i++) { if (i == itemCount / 2) { middleNode = list.AddLast(i); } else { list.AddLast(i); } } for (int i = 0; i < itemCount; i++) { list.AddAfter(middleNode, i); } int j = 0; int k = 0; int numberOfElementsInList = 0; foreach (var item in list) { if (j <= itemCount / 2) { if (j != item) { Assert.Fail("1"); } } else if (j > itemCount / 2 && j <= itemCount + itemCount / 2) { if (itemCount - 1 - k++ != item) { Assert.Fail("2"); } } else { if (j - itemCount != item) { Assert.Fail("3"); } } j++; numberOfElementsInList++; } Assert.IsTrue(list.Count == 2 * itemCount && numberOfElementsInList == list.Count); }
public void AddAfterNullNodeTest() { DoublyLinkedList <int> dll = new DoublyLinkedList <int> { 10 }; dll.AddAfter(null, 10); }
public void InsertAfter() { IDoublyLinkedList <int> list = new DoublyLinkedList <int>(); list.AddFirst(new DoublyLinkedListNode <int>(22)); list.AddAfter(22, new DoublyLinkedListNode <int>(1)); Assert.AreEqual(list.FindLastNode().Value, 1); }
public void AddAfterTailTest() { DoublyLinkedList<int> dll = new DoublyLinkedList<int> {10}; dll.AddAfter(dll.Head, 20); Assert.AreEqual(20, dll.Tail.Value); Assert.AreEqual(10, dll.Tail.Previous.Value); }
public void AddAfterTailPUT([PexAssumeUnderTest]IList<int> values, int toAddValue) { PexAssume.IsTrue(values.Count > 1); PexAssume.IsFalse(values.Contains(toAddValue)); DoublyLinkedList<int> dll = new DoublyLinkedList<int> (values); dll.AddAfter(dll.Tail, toAddValue); PexAssert.AreEqual(toAddValue, dll.Tail.Value); PexAssert.AreEqual(values[values.Count - 1], dll.Tail.Previous.Value); }
public void AddAfterTailPUT([PexAssumeUnderTest] IList <int> values, int toAddValue) { PexAssume.IsTrue(values.Count > 1); PexAssume.IsFalse(values.Contains(toAddValue)); DoublyLinkedList <int> dll = new DoublyLinkedList <int> (values); dll.AddAfter(dll.Tail, toAddValue); PexAssert.AreEqual(toAddValue, dll.Tail.Value); PexAssert.AreEqual(values[values.Count - 1], dll.Tail.Previous.Value); }
public void FindFirstTest() { var list = new DoublyLinkedList <int>(); var node = list.AddFirst(1); node = list.AddAfter(node, 2); node = list.FindFirst(2); Assert.IsTrue(node != null, "Node find incorrect"); }
public void AddAfterTailTest() { DoublyLinkedList <int> dll = new DoublyLinkedList <int> { 10 }; dll.AddAfter(dll.Head, 20); Assert.AreEqual(20, dll.Tail.Value); Assert.AreEqual(10, dll.Tail.Previous.Value); }
public void AddAfterTest() { DoublyLinkedList<int> dll = new DoublyLinkedList<int> {10, 20, 30}; dll.AddAfter(dll.Head.Next, 25); Assert.AreEqual(25, dll.Head.Next.Next.Value); Assert.AreEqual(20, dll.Head.Next.Next.Previous.Value); Assert.AreEqual(30, dll.Head.Next.Next.Next.Value); Assert.AreEqual(25, dll.Tail.Previous.Value); }
static void Main(string[] args) { //싱글 링크드리스트 테스트 SinglyLinkedList <int> singlyList = new SinglyLinkedList <int>(); var node1 = new SinglyLinkedListNode <int>(1); var node2 = new SinglyLinkedListNode <int>(2); var node3 = new SinglyLinkedListNode <int>(3); var node4 = new SinglyLinkedListNode <int>(4); var node5 = new SinglyLinkedListNode <int>(5); singlyList.Add(node1); singlyList.Add(node2); singlyList.Add(node3); singlyList.Add(node4); singlyList.Show(); singlyList.Remove(node2); singlyList.Remove(node4); singlyList.Show(); //더블 원형 링크드리스트 테스트 DoublyLinkedList <int> doubleList = new DoublyLinkedList <int>(); var doublyNode1 = new DoublyLinkedNode <int>(1); var doublyNode2 = new DoublyLinkedNode <int>(2); var doublyNode3 = new DoublyLinkedNode <int>(3); var doublyNode4 = new DoublyLinkedNode <int>(4); var doublyNode5 = new DoublyLinkedNode <int>(5); doubleList.Add(doublyNode1); doubleList.Add(doublyNode3); doubleList.AddAfter(doublyNode1, doublyNode2); doubleList.AddAfter(doublyNode3, doublyNode4); doubleList.Add(doublyNode5); doubleList.Remove(doubleList.GetNode(0)); Console.WriteLine(doubleList.Count); Console.WriteLine("\n"); for (int i = 0; i < doubleList.Count; ++i) { Console.WriteLine(doubleList.GetNode(i).Data); } }
//рекурсивный метод, который добавляет новый элемент после prevNode, если добавление этого элемента законно, далее вызывает себя //для prevNode и нового узла. выход из рекурсии, когда добавление элемента невозможно, т.е. при знаменателе большем n static void ModifyList(int n, DoublyLinkedList <Tuple <int, int> > list, DoublyLinkedListNode <Tuple <int, int> > prevNode) { if ((prevNode.Value.Item2 + prevNode.Next.Value.Item2) <= n) { list.AddAfter(prevNode, Tuple.Create( prevNode.Value.Item1 + prevNode.Next.Value.Item1, prevNode.Value.Item2 + prevNode.Next.Value.Item2 )); var next = prevNode.Next; ModifyList(n, list, prevNode); ModifyList(n, list, next); } }
public void AddAfterTest() { DoublyLinkedList <int> dll = new DoublyLinkedList <int> { 10, 20, 30 }; dll.AddAfter(dll.Head.Next, 25); Assert.AreEqual(25, dll.Head.Next.Next.Value); Assert.AreEqual(20, dll.Head.Next.Next.Previous.Value); Assert.AreEqual(30, dll.Head.Next.Next.Next.Value); Assert.AreEqual(25, dll.Tail.Previous.Value); }
void InvalidNode() { // Arrange var list = new DoublyLinkedList <int>(); var anotherList = new DoublyLinkedList <int>(new int[] { 1 }); var node = anotherList.Find(1); // Act Action action = () => list.AddAfter(node, 1); // Assert action.Should().ThrowExactly <InvalidOperationException>(); }
public void AddAfterPUT([PexAssumeUnderTest]IList<int> values, int toAddValue) { PexAssume.IsFalse(values.Contains(toAddValue)); DoublyLinkedList<int> dll = new DoublyLinkedList<int>(values); if (values.Count == 0) { dll.AddAfter(dll.Head, toAddValue); PexAssert.IsFalse(true, "InvalidOperationException was expected"); } dll.AddAfter(dll.Head.Next, toAddValue); if (values.Count == 1) { PexAssert.IsFalse(true, "ArgumentNullException was expected"); } PexAssert.AreEqual(toAddValue, dll.Head.Next.Next.Value); PexAssert.AreEqual(values[1], dll.Head.Next.Next.Previous.Value); if (values.Count > 2) { PexAssert.AreEqual(values[2], dll.Head.Next.Next.Next.Value); if (values.Count == 3) PexAssert.AreEqual(toAddValue, dll.Tail.Previous.Value); } }
public void AddNullItem() { var list = new DoublyLinkedList <string>(); list.AddFirst(null); list.AddLast(null); list.AddAfter(null, null); list.AddBefore(null, null); Assert.AreEqual(list.Count(), 4, "invalid count"); list.Remove(null); list.RemoveFirst(); list.RemoveLast(); Assert.AreEqual(list.Count(), 1, "invalid count"); }
public static void TestAddtion() { var dll = new DoublyLinkedList <int>(0); var one = dll.Add(1); dll.Add(3); dll.AddAfter(2, one); dll.Add(4); var arr = dll.GetData().ToArray(); Assert.AreEqual(dll.Count, 5); Assert.AreEqual(new[] { 0, 1, 2, 3, 4 }, arr); }
public void CountTest() { DoublyLinkedList <int> dll = new DoublyLinkedList <int> { 10, 5 }; dll.RemoveFirst(); dll.RemoveLast(); dll.Add(10); dll.AddAfter(dll.Head, 30); dll.AddBefore(dll.Head.Next, 20); Assert.AreEqual(3, dll.Count); }
void NullNode() { // Arrange var list = new DoublyLinkedList <int>(); // Act Action action = () => list.AddAfter(null, 1); // Assert action.Must() .Throw <ArgumentNullException>() .EvaluatesTrue(exception => exception.ParamName == "node"); }
public void CountPUT([PexAssumeUnderTest] IList <int> values, int randomPick1) { PexAssume.IsFalse(values.Contains(randomPick1)); PexAssume.IsTrue(values.Count > 1); DoublyLinkedList <int> dll = new DoublyLinkedList <int> (values); dll.RemoveFirst(); dll.RemoveLast(); PexAssert.AreEqual(values.Count - 2, dll.Count); dll.Add(randomPick1); dll.AddAfter(dll.Head, values[0]); dll.AddBefore(dll.Head.Next, values[values.Count - 1]); PexAssert.AreEqual(values.Count + 1, dll.Count); }
public void Test_DoublyLinkedList_AddAfter() { // Arrange StringBuilder stringBuilder = new StringBuilder("ABB1C"); // Act _doublyLinkedList.Add("A"); var linkB = _doublyLinkedList.Add("B"); _doublyLinkedList.Add("C"); _doublyLinkedList.AddAfter(linkB, "B1"); // Assert Assert.AreEqual(stringBuilder.ToString(), _doublyLinkedList.ToString()); }
public void CanAddAfterSpecificElement() { DoublyLinkedList <int> doublyLinkedList = new DoublyLinkedList <int>(5); doublyLinkedList.AddLast(7); doublyLinkedList.AddLast(13); Assert.AreEqual(5, doublyLinkedList.First.Value); doublyLinkedList.AddAfter(7, 100); string expectedOutput = "5 7 100 13"; string output = doublyLinkedList.ToString().Trim(); Assert.AreEqual(expectedOutput, output); }
void NullNode() { // Arrange var list = new DoublyLinkedList <int>(); // Act Action action = () => list.AddAfter(null, 1); // Assert action.Should() .ThrowExactly <ArgumentNullException>() .And .ParamName.Should() .Be("node"); }
void AddItem(IReadOnlyList <int> collection, int after, int item, IReadOnlyList <int> expected) { // Arrange var list = new DoublyLinkedList <int>(collection); var version = list.Version; var node = list.Find(after); // Act list.AddAfter(node, item); // Assert list.Count.Should().Be(expected.Count); list.Version.Should().NotBe(version); list.EnumerateForward().Should().Equal(expected); list.EnumerateReversed().Should().Equal(expected.Reverse()); }
private static void Run() { var doublyLinkedList = new DoublyLinkedList <int>(); var firstNode = new LinkedListNode <int>(10); var secondNode = new LinkedListNode <int>(20); var thirdNode = new LinkedListNode <int>(30); var forthNode = new LinkedListNode <int>(40); doublyLinkedList.Add(firstNode); doublyLinkedList.Add(secondNode); doublyLinkedList.Add(forthNode); doublyLinkedList.AddAfter(secondNode, thirdNode); doublyLinkedList.Remove(firstNode); PrintAllElements(doublyLinkedList); }
void AddItem(IReadOnlyList <int> collection, int after, int item, IReadOnlyList <int> expected) { // Arrange var list = new DoublyLinkedList <int>(collection); var version = list.Version; var node = list.Find(after); // Act list.AddAfter(node, item); // Assert list.Version.Must() .BeNotEqualTo(version); list.EnumerateForward().Must() .BeEnumerableOf <int>() .BeEqualTo(expected); list.EnumerateReversed().Must() .BeEnumerableOf <int>() .BeEqualTo(expected.Reverse()); }
public void Test() { DoublyLinkedList <int> list1 = new DoublyLinkedList <int>(); Console.WriteLine("Count: " + list1.Count); list1.AddFirst(1); list1.AddFirst(0); list1.AddFirst(-1); list1.AddLast(2); list1.AddLast(4); var node = list1.Find(4); list1.AddBefore(node, 3); Console.WriteLine(list1.ToString()); list1.AddAfter(node, 5); Console.WriteLine(list1.ToString()); Console.WriteLine("List contains 2 - " + (list1.Contains(2) ? "TRUE" : "FALSE")); Console.WriteLine("List contains 6 - " + (list1.Contains(6) ? "TRUE" : "FALSE")); list1.Remove(0); list1.RemoveFirst(); list1.RemoveFirst(); list1.RemoveLast(); Console.WriteLine("Count: " + list1.Count); Console.WriteLine(list1.ToString()); DoublyLinkedList <string> list2 = new DoublyLinkedList <string>(new string[] { "abcde", "abcdefg", "bcd" }); Console.WriteLine(list2.ToString()); }
public void AddAfterNoNodesTest() { DoublyLinkedList<int> dll = new DoublyLinkedList<int>(); dll.AddAfter(dll.Head, 10); }
public void CountTest() { DoublyLinkedList<int> dll = new DoublyLinkedList<int> {10, 5}; dll.RemoveFirst(); dll.RemoveLast(); dll.Add(10); dll.AddAfter(dll.Head, 30); dll.AddBefore(dll.Head.Next, 20); Assert.AreEqual(3, dll.Count); }
public void AddAfterNullNodeTest() { DoublyLinkedList<int> dll = new DoublyLinkedList<int> {10}; dll.AddAfter(null, 10); }
public void CountPUT([PexAssumeUnderTest]IList<int> values, int randomPick1) { PexAssume.IsFalse(values.Contains(randomPick1)); PexAssume.IsTrue(values.Count > 1); DoublyLinkedList<int> dll = new DoublyLinkedList<int> (values); dll.RemoveFirst(); dll.RemoveLast(); PexAssert.AreEqual(values.Count-2, dll.Count); dll.Add(randomPick1); dll.AddAfter(dll.Head, values[0]); dll.AddBefore(dll.Head.Next, values[values.Count-1]); PexAssert.AreEqual(values.Count+1, dll.Count); }
public void AddAfterNoNodesTest() { DoublyLinkedList <int> dll = new DoublyLinkedList <int>(); dll.AddAfter(dll.Head, 10); }