File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
DataStructures.Tests/LinkedList Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,27 @@ public static void TestInsertAfterOnNonExistingValue()
90
90
Assert . That ( "10" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
91
91
}
92
92
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
+
93
114
[ Test ]
94
115
public static void TestDeleteNode ( )
95
116
{
You can’t perform that action at this time.
0 commit comments