-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_0206_Reverse_linked_list_Test.cs
More file actions
74 lines (59 loc) · 1.87 KB
/
_0206_Reverse_linked_list_Test.cs
File metadata and controls
74 lines (59 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Solution._0206.Reverse_linked_list;
using Common;
using FluentAssertions;
namespace _0206.Reverse_linked_list.Tests
{
[TestClass()]
public class _0206_Reverse_linked_list_Test
{
_0206_Reverse_linked_list solution = new _0206_Reverse_linked_list();
[TestMethod()]
public void ReverseList_Test1()
{
// Arrange
ListNode head = AddNode(new int[] { 1, 2, 3, 4, 5 });
var expected = AddNode(new int[] { 5, 4, 3, 2, 1 });
// Act
var actual = solution.ReverseList(head);
// Assert
actual.Should().BeEquivalentTo(expected);
}
[TestMethod()]
public void ReverseList_Test2()
{
// Arrange
ListNode head = AddNode(new int[] { 1, 2 });
var expected = AddNode(new int[] { 2, 1 });
// Act
var actual = solution.ReverseList(head);
// Assert
actual.Should().BeEquivalentTo(expected);
}
[TestMethod()]
public void ReverseList_Test3()
{
// Arrange
ListNode head = AddNode(new int[] { });
var expected = AddNode(new int[] { });
// Act
var actual = solution.ReverseList(head);
// Assert
actual.Should().BeEquivalentTo(expected);
}
private ListNode AddNode(int[] arr)
{
if (arr.Length <= 0)
return new ListNode();
ListNode res = new ListNode(arr[0]);
ListNode current = res;
for (int i = 1; i < arr.Length; i++)
{
ListNode newNode = new ListNode(arr[i]);
current.next = newNode;
current = current.next;
}
return res;
}
}
}