Skip to content

[REFACTOR] test code de-duplication. #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class LinkedListCycleTest
class LinkedListCycleTestCase
{
public string title = "";
public LinkedList<int>.Node? llist;
public LinkedList<string>.Node? llist;
public bool expected;
}

Expand All @@ -16,21 +16,21 @@ class LinkedListCycleTestCase
public void testInitialize()
{
// Linked list sample data:
LinkedList<int>.Node ll1_1 = new(1);
LinkedList<int>.Node ll1_2 = new(2);
LinkedList<int>.Node ll1_3 = new(3);
LinkedList<int>.Node ll1_4 = new(4);
LinkedList<int>.Node ll1_5 = new(5);
LinkedList<string>.Node ll1_1 = new("a");
LinkedList<string>.Node ll1_2 = new("b");
LinkedList<string>.Node ll1_3 = new("c");
LinkedList<string>.Node ll1_4 = new("d");
LinkedList<string>.Node ll1_5 = new("e");

ll1_1.next = ll1_2;
ll1_2.next = ll1_3;
ll1_3.next = ll1_4;
ll1_4.next = ll1_5;
ll1_4.next = ll1_3; // <- cycle

LinkedList<int>.Node ll2_1 = new(1);
LinkedList<int>.Node ll2_2 = new(2);
LinkedList<int>.Node ll2_3 = new(3);
LinkedList<string>.Node ll2_1 = new("a");
LinkedList<string>.Node ll2_2 = new("b");
LinkedList<string>.Node ll2_3 = new("c");

ll2_1.next = ll2_2;
ll2_2.next = ll2_3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class LinkedListCycle
[ExcludeFromCodeCoverage]
protected LinkedListCycle() { }

public static bool hasCycle(LinkedList<int>.Node? head)
public static bool hasCycle<T>(LinkedList<T>.Node? head)
{
List<LinkedList<int>.Node> llindex = [];
List<LinkedList<T>.Node> llindex = [];

LinkedList<int>.Node? node = head;
LinkedList<T>.Node? node = head;

while (node != null)
{
Expand Down