Skip to content

Commit 3e302c6

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] File may only contain a single type. (SA1402)
1 parent 1beba2e commit 3e302c6

File tree

3 files changed

+28
-24
lines changed
  • src
    • algorithm_exercises_csharp/hackerrank/interview_preparation_kit/linked_list/lib
    • algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/linked_list/lib

3 files changed

+28
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.linked_list.lib;
2+
3+
public static class LinkedListPrinter
4+
{
5+
public static void printSinglyLinkedList<T>(LinkedList<T>.Node? node, string sep, TextWriter textWriter)
6+
{
7+
var pointTo = node;
8+
9+
while (pointTo != null)
10+
{
11+
textWriter.Write(pointTo.data);
12+
13+
pointTo = pointTo.next;
14+
15+
if (pointTo != null)
16+
{
17+
textWriter.Write(sep);
18+
}
19+
}
20+
}
21+
}
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit.linked_list.lib;
22

3-
public class LinkedList<T>
3+
public static class LinkedList<T>
44
{
55
public class Node(T nodeData)
66
{
77
public T data { get; set; } = nodeData;
8-
public Node? next { get; set; } = null;
9-
}
10-
11-
public static void printSinglyLinkedList(Node? node, string sep, TextWriter textWriter)
12-
{
13-
Node? pointTo = node;
14-
15-
while (pointTo != null)
16-
{
17-
textWriter.Write(pointTo.data);
18-
19-
pointTo = pointTo.next;
20-
21-
if (pointTo != null)
22-
{
23-
textWriter.Write(sep);
24-
}
25-
}
8+
public Node? next { get; set; } = default!;
269
}
2710
}

src/algorithm_exercises_csharp_test/hackerrank/interview_preparation_kit/linked_list/lib/Node.Test.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace algorithm_exercises_csharp_test.hackerrank.interview_preparation_kit.l
44
[TestClass]
55
public class NodeTest
66
{
7-
class NodeTestCase
7+
private sealed class NodeTestCase
88
{
99
public string title = "";
1010
public LinkedList<int>.Node? llist;
@@ -45,15 +45,15 @@ public void testPrintLinkedList()
4545
{
4646
foreach (NodeTestCase test in tests)
4747
{
48-
StringWriter sw = new();
49-
50-
LinkedList<int>.printSinglyLinkedList(test.llist, test.separator, sw);
48+
using StringWriter sw = new();
49+
LinkedListPrinter.printSinglyLinkedList<int>(test.llist, test.separator, sw);
5150

5251
string result = sw.ToString();
5352
Assert.AreEqual(
5453
test.expected,
5554
result,
56-
String.Format(
55+
string.Format(
56+
System.Globalization.CultureInfo.InvariantCulture,
5757
"{0} testPrintLinkedList<int>(<Node>, {1}, <Textwriter>) => must be: {2}",
5858
test.title,
5959
test.separator,

0 commit comments

Comments
 (0)