/
TestMergeSortedLinkedLists.cs
228 lines (188 loc) · 6.39 KB
/
TestMergeSortedLinkedLists.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace CL_MergeSortedLinkedLists
{
class TestMergeSortedLinkedLists
{
[Test]
public void Add_from123_add4return1234()
{
Node nodes = new Node();
nodes.data = 1;
nodes.next = new Node();
nodes.next.data = 2;
nodes.next.next = new Node();
nodes.next.next.data = 3;
nodes.next.next.next = null;
Node newnode = new Node();
newnode.data = 4;
newnode.next = null;
var actual = String.Empty;
var expected = "1,2,3,4";
var sortProcessor = new MergeSortedLinkedLists();
var actNode = sortProcessor.appendForTest(nodes,newnode);
actual = sortProcessor.printData(actNode);
Assert.AreEqual(expected, actual);
}
[Test]
public void Add_from1_add234return1234()
{
Node node1 = new Node();
node1.data = 1;
node1.next = null;
Node newnodes = new Node();
newnodes.data = 2;
newnodes.next = new Node();
newnodes.next.data = 3;
newnodes.next.next = new Node();
newnodes.next.next.data = 4;
newnodes.next.next.next = null;
var actual = String.Empty;
var expected = "1,2,3,4";
var sortProcessor = new MergeSortedLinkedLists();
var actNode = sortProcessor.appendForTest(node1, newnodes);
actual = sortProcessor.printData(actNode);
Assert.AreEqual(expected, actual);
}
[Test]
public void printData_nullresult_returnEmpty()
{
// Arrange
Node node1 = null;
var sortProcessor = new MergeSortedLinkedLists();
var actual = String.Empty;
var expected = String.Empty;
// Act
actual = sortProcessor.printData(node1);
// Assert
Assert.AreEqual(expected, actual);
}
[Test]
public void printData()
{
// Arrange
// head1 = 3,4,1
Node node1 = new Node();
node1.data = 1;
node1.next = null;
Node node4 = new Node();
node4.data = 4;
node4.next = node1;
Node node3 = new Node();
node3.data = 3;
node3.next = node4;
var sortProcessor = new MergeSortedLinkedLists();
var actual = String.Empty;
var expected = "3,4,1";
// Act
actual = sortProcessor.printData(node3);
// Assert
Assert.AreEqual(expected,actual);
}
[Test]
public void Merge_2NullArray_RetNull()
{
// Arrange
// head1 = null
// head2 = null
Node head1 = null;
Node head2 = null;
var sortProcessor = new MergeSortedLinkedLists();
Node actualNode = null;
// Act
actualNode = sortProcessor.Merge(head1, head2);
// Assert
Assert.Null(actualNode);
}
[Test]
public void Merge_head1Null_Rethead2()
{
// Arrange
// head1 = null
// head2 = null
Node head1 = null;
Node node3 = new Node();
node3.data = 3;
node3.next = null;
Node node2 = new Node();
node2.data = 2;
node2.next = node3;
Node node1 = new Node();
node1.data = 1;
node1.next = node2;
Node head2 = node1;
var sortProcessor = new MergeSortedLinkedLists();
Node actualNode = sortProcessor.Merge(head1,head2);
var actual = sortProcessor.printData(actualNode);
var expected = "1,2,3";
// Act
actualNode = sortProcessor.Merge(head1, head2);
// Assert
Assert.AreEqual(expected,actual);
}
[Test]
public void Merge_head1_134_head2_25_return_12345()
{
// Arrange
// head1 = 1,3,4
// head2 = 2,5
Node head1 = new Node();
head1.data = 1;
head1.next = new Node();
head1.next.data = 3;
head1.next.next = new Node();
head1.next.next.data = 4;
head1.next.next.next = null;
Node head2 = new Node();
head2.data = 2;
head2.next = new Node();
head2.next.data = 5;
head2.next.next = null;
var sortProcessor = new MergeSortedLinkedLists();
var actualNode = new Node();
var actual = String.Empty;
var expected = "1,2,3,4,5";
// Act
actualNode = sortProcessor.Merge(head1, head2);
actual = sortProcessor.printData(actualNode);
// Assert
Assert.AreEqual(expected, actual);
}
[Test]
public void Merge_head1_134_head2_2567_return_1234567()
{
// Arrange
// head1 = 1,3,4
// head2 = 2,5
Node head1 = new Node();
head1.data = 1;
head1.next = new Node();
head1.next.data = 3;
head1.next.next = new Node();
head1.next.next.data = 4;
head1.next.next.next = null;
Node head2 = new Node();
head2.data = 2;
head2.next = new Node();
head2.next.data = 5;
head2.next.next = new Node();
head2.next.next.data = 6;
head2.next.next.next = new Node();
head2.next.next.next.data = 7;
head2.next.next.next.next = null;
var sortProcessor = new MergeSortedLinkedLists();
var actualNode = new Node();
var actual = String.Empty;
var expected = "1,2,3,4,5,6,7";
// Act
actualNode = sortProcessor.Merge(head1, head2);
actual = sortProcessor.printData(actualNode);
// Assert
Assert.AreEqual(expected, actual);
}
}
}