From 75f923327509d01d111912598467d6db53231ac4 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Sun, 13 Oct 2024 10:32:28 +0530 Subject: [PATCH] added test case for codecov --- .../LinkedList/CircularLinkedListTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/DataStructures.Tests/LinkedList/CircularLinkedListTests.cs b/DataStructures.Tests/LinkedList/CircularLinkedListTests.cs index 98d4a7cc..e97bc16b 100644 --- a/DataStructures.Tests/LinkedList/CircularLinkedListTests.cs +++ b/DataStructures.Tests/LinkedList/CircularLinkedListTests.cs @@ -90,6 +90,27 @@ public static void TestInsertAfterOnNonExistingValue() Assert.That("10", Is.EqualTo(GetDisplayOutput(cll).Trim())); } + [Test] + public static void TestInsertAfterTailNode() + { + var cll = new CircularLinkedList(); + cll.InsertAtEnd(10); // tail -> 10 + cll.InsertAtEnd(20); // tail -> 20 + cll.InsertAtEnd(30); // tail -> 30 + + // Insert after the current tail (30) + cll.InsertAfter(30, 40); // This should make 40 the new tail + + // Now 40 should be the tail, and the list should be 10 20 30 40 + Assert.That("10 20 30 40", Is.EqualTo(GetDisplayOutput(cll).Trim())); + + // Additionally, assert that tail's Data is now 40 + var tailField = typeof(CircularLinkedList).GetField("tail", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); + var tailNode = (CircularLinkedListNode?)tailField?.GetValue(cll); + Assert.That(tailNode!.Data, Is.EqualTo(40)); // tail should now point to 40 + } + + [Test] public static void TestDeleteNode() {