@@ -7,6 +7,17 @@ namespace DataStructures.Tests.LinkedList;
7
7
[ TestFixture ]
8
8
public static class CircularLinkedListTests
9
9
{
10
+ [ Test ]
11
+ public static void TestDisplay ( )
12
+ {
13
+ var cll = new CircularLinkedList < int > ( ) ;
14
+ cll . InsertAtEnd ( 10 ) ;
15
+ cll . InsertAtEnd ( 20 ) ;
16
+ cll . InsertAtEnd ( 30 ) ;
17
+
18
+ Assert . That ( "10 20 30" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
19
+ }
20
+
10
21
[ Test ]
11
22
public static void TestInsertAtBeginning ( )
12
23
{
@@ -42,51 +53,53 @@ public static void TestInsertAfter()
42
53
}
43
54
44
55
[ Test ]
45
- public static void TestDeleteNode ( )
56
+ public static void TestInsertAtBeginningInEmptyList ( )
46
57
{
47
58
var cll = new CircularLinkedList < int > ( ) ;
48
- cll . InsertAtEnd ( 10 ) ;
49
- cll . InsertAtEnd ( 20 ) ;
50
- cll . InsertAtEnd ( 30 ) ;
51
-
52
- cll . DeleteNode ( 20 ) ;
53
- Assert . That ( "10 30" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
59
+ cll . InsertAtBeginning ( 10 ) ;
60
+ Assert . That ( "10" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
54
61
}
55
62
56
63
[ Test ]
57
- public static void TestDisplay ( )
64
+ public static void TestInsertAtEndInEmptyList ( )
58
65
{
59
66
var cll = new CircularLinkedList < int > ( ) ;
60
67
cll . InsertAtEnd ( 10 ) ;
61
- cll . InsertAtEnd ( 20 ) ;
62
- cll . InsertAtEnd ( 30 ) ;
63
68
64
- Assert . That ( "10 20 30 " , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
69
+ Assert . That ( "10" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
65
70
}
66
71
67
72
[ Test ]
68
- public static void TestDeleteFromEmptyList ( )
73
+ public static void TestInsertAfterSpecificNode ( )
69
74
{
70
75
var cll = new CircularLinkedList < int > ( ) ;
71
- cll . DeleteNode ( 10 ) ;
72
- Assert . That ( cll . IsEmpty ( ) , Is . EqualTo ( true ) ) ;
76
+ cll . InsertAtEnd ( 10 ) ;
77
+ cll . InsertAtEnd ( 20 ) ;
78
+ cll . InsertAtEnd ( 30 ) ;
79
+
80
+ cll . InsertAfter ( 20 , 25 ) ; // Insert after node with value 20
81
+ Assert . That ( "10 20 25 30" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
73
82
}
74
83
75
84
[ Test ]
76
- public static void TestInsertInEmptyList ( )
85
+ public static void TestInsertAfterOnNonExistingValue ( )
77
86
{
78
87
var cll = new CircularLinkedList < int > ( ) ;
79
- cll . InsertAtBeginning ( 10 ) ;
88
+ cll . InsertAtEnd ( 10 ) ;
89
+ cll . InsertAfter ( 99 , 25 ) ; // 99 does not exist
80
90
Assert . That ( "10" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
81
91
}
82
92
83
93
[ Test ]
84
- public static void TestInsertAfterOnNonExistingValue ( )
94
+ public static void TestDeleteNode ( )
85
95
{
86
96
var cll = new CircularLinkedList < int > ( ) ;
87
97
cll . InsertAtEnd ( 10 ) ;
88
- cll . InsertAfter ( 99 , 25 ) ; // 99 does not exist
89
- Assert . That ( "10" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
98
+ cll . InsertAtEnd ( 20 ) ;
99
+ cll . InsertAtEnd ( 30 ) ;
100
+
101
+ cll . DeleteNode ( 20 ) ;
102
+ Assert . That ( "10 30" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
90
103
}
91
104
92
105
[ Test ]
@@ -120,6 +133,26 @@ public static void TestDeleteTailNode()
120
133
Assert . That ( "10 20" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
121
134
}
122
135
136
+ [ Test ]
137
+ public static void TestDeleteFromEmptyList ( )
138
+ {
139
+ var cll = new CircularLinkedList < int > ( ) ;
140
+ cll . DeleteNode ( 10 ) ;
141
+ Assert . That ( cll . IsEmpty ( ) , Is . EqualTo ( true ) ) ;
142
+ }
143
+
144
+ [ Test ]
145
+ public static void TestDeleteNonExistentNode ( )
146
+ {
147
+ var cll = new CircularLinkedList < int > ( ) ;
148
+ cll . InsertAtEnd ( 10 ) ;
149
+ cll . InsertAtEnd ( 20 ) ;
150
+ cll . InsertAtEnd ( 30 ) ;
151
+
152
+ cll . DeleteNode ( 40 ) ; // Attempting to delete a node that doesn't exist
153
+ Assert . That ( "10 20 30" , Is . EqualTo ( GetDisplayOutput ( cll ) . Trim ( ) ) ) ;
154
+ }
155
+
123
156
/// <summary>
124
157
/// Helper method to capture the output of the Display method for assertions.
125
158
/// </summary>
0 commit comments