Skip to content

Commit 9684551

Browse files
Codacy issue resolution and added test cases for codecov
1 parent d99a422 commit 9684551

File tree

2 files changed

+53
-20
lines changed

2 files changed

+53
-20
lines changed

DataStructures.Tests/LinkedList/CircularLinkedListTests.cs

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ namespace DataStructures.Tests.LinkedList;
77
[TestFixture]
88
public static class CircularLinkedListTests
99
{
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+
1021
[Test]
1122
public static void TestInsertAtBeginning()
1223
{
@@ -42,51 +53,53 @@ public static void TestInsertAfter()
4253
}
4354

4455
[Test]
45-
public static void TestDeleteNode()
56+
public static void TestInsertAtBeginningInEmptyList()
4657
{
4758
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()));
5461
}
5562

5663
[Test]
57-
public static void TestDisplay()
64+
public static void TestInsertAtEndInEmptyList()
5865
{
5966
var cll = new CircularLinkedList<int>();
6067
cll.InsertAtEnd(10);
61-
cll.InsertAtEnd(20);
62-
cll.InsertAtEnd(30);
6368

64-
Assert.That("10 20 30", Is.EqualTo(GetDisplayOutput(cll).Trim()));
69+
Assert.That("10", Is.EqualTo(GetDisplayOutput(cll).Trim()));
6570
}
6671

6772
[Test]
68-
public static void TestDeleteFromEmptyList()
73+
public static void TestInsertAfterSpecificNode()
6974
{
7075
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()));
7382
}
7483

7584
[Test]
76-
public static void TestInsertInEmptyList()
85+
public static void TestInsertAfterOnNonExistingValue()
7786
{
7887
var cll = new CircularLinkedList<int>();
79-
cll.InsertAtBeginning(10);
88+
cll.InsertAtEnd(10);
89+
cll.InsertAfter(99, 25); // 99 does not exist
8090
Assert.That("10", Is.EqualTo(GetDisplayOutput(cll).Trim()));
8191
}
8292

8393
[Test]
84-
public static void TestInsertAfterOnNonExistingValue()
94+
public static void TestDeleteNode()
8595
{
8696
var cll = new CircularLinkedList<int>();
8797
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()));
90103
}
91104

92105
[Test]
@@ -120,6 +133,26 @@ public static void TestDeleteTailNode()
120133
Assert.That("10 20", Is.EqualTo(GetDisplayOutput(cll).Trim()));
121134
}
122135

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+
123156
/// <summary>
124157
/// Helper method to capture the output of the Display method for assertions.
125158
/// </summary>

DataStructures/LinkedList/CircularLinkedList/CircularLinkedListNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ public class CircularLinkedListNode<T>(T data)
1919
/// <summary>
2020
/// Gets or sets the reference to the next node in the list.
2121
/// </summary>
22-
public CircularLinkedListNode<T>? Next { get; set; } = null;
22+
public CircularLinkedListNode<T>? Next { get; set; }
2323
}
2424
}

0 commit comments

Comments
 (0)