Skip to content

Commit 75f9233

Browse files
added test case for codecov
1 parent e50aed7 commit 75f9233

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

DataStructures.Tests/LinkedList/CircularLinkedListTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ public static void TestInsertAfterOnNonExistingValue()
9090
Assert.That("10", Is.EqualTo(GetDisplayOutput(cll).Trim()));
9191
}
9292

93+
[Test]
94+
public static void TestInsertAfterTailNode()
95+
{
96+
var cll = new CircularLinkedList<int>();
97+
cll.InsertAtEnd(10); // tail -> 10
98+
cll.InsertAtEnd(20); // tail -> 20
99+
cll.InsertAtEnd(30); // tail -> 30
100+
101+
// Insert after the current tail (30)
102+
cll.InsertAfter(30, 40); // This should make 40 the new tail
103+
104+
// Now 40 should be the tail, and the list should be 10 20 30 40
105+
Assert.That("10 20 30 40", Is.EqualTo(GetDisplayOutput(cll).Trim()));
106+
107+
// Additionally, assert that tail's Data is now 40
108+
var tailField = typeof(CircularLinkedList<int>).GetField("tail", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
109+
var tailNode = (CircularLinkedListNode<int>?)tailField?.GetValue(cll);
110+
Assert.That(tailNode!.Data, Is.EqualTo(40)); // tail should now point to 40
111+
}
112+
113+
93114
[Test]
94115
public static void TestDeleteNode()
95116
{

0 commit comments

Comments
 (0)