-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicListTests.cs
257 lines (213 loc) · 10.1 KB
/
DynamicListTests.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
namespace DynamicList.test
{
using System;
using CustomLinkedList;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class DynamicListTests
{
[TestMethod]
public void GettingEmptyDynamicListOfIntsShouldReturnEmptyDynamicListOfIntsWhitZeroCount()
{
var dynamicListOfInts = new DynamicList<int>();
Assert.AreEqual(0, dynamicListOfInts.Count, string.Format("Default count of DynamicList must be 0 not: {0}.", dynamicListOfInts.Count));
}
[TestMethod]
public void AddingNewItemsSeveralTimesInDynamicListShouldReturnCountPlusThree()
{
var dynamicListOfStrings = new DynamicList<string>();
int coutBeforAdding = dynamicListOfStrings.Count;
dynamicListOfStrings.Add("0");
dynamicListOfStrings.Add("1, 2 , 3");
dynamicListOfStrings.Add("4");
Assert.AreEqual(3, dynamicListOfStrings.Count, "The method \"Add\" does not work correctly");
}
[TestMethod]
public void GetingElementAtCorrectPositionFromNoneEmptyDynamicListOfIntsShouldReturnCorrectElement()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
Assert.AreEqual(3, dynamicListOfInts[2],
"Obtained value of getting a element whit operator \"[]\" is not as expected." +
"\nNote that position couting should start from 0!");
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), "That Exception is not expected")]
public void GettingElementAtOutOfRangePositionFromNoneEmptyDynamicListOfIntsShouldThrowException()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
var outOfRangePosition = dynamicListOfInts[4];
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), "That Exception is not expected")]
public void GettingElementAtNegativePositionFromNoneEmptyDynamicListOfIntsShouldThrowException()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
var negativePosition = dynamicListOfInts[-1];
}
[TestMethod]
public void SettingElementAtCorrectPositionInNoneEmptyDynamicListOfIntsShouldReturnCorrectElements()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(0);
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
int startingCount = dynamicListOfInts.Count;
dynamicListOfInts[0] = 1;
bool isSettingAtPositionCorrect =
dynamicListOfInts[0] == 1 &&
dynamicListOfInts[1] == 1 &&
dynamicListOfInts[2] == 2 &&
dynamicListOfInts.Count == startingCount;
Assert.AreEqual(true, isSettingAtPositionCorrect,
string.Format("Operator \"[]\" does not work correctly when sets a element"));
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), "That Exception is not expected")]
public void SettingElementAtOutOfRangePositionInNoneEmptyDynamicListOfIntsShouldThrowException()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
dynamicListOfInts[4] = 4;
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), "That Exception is not expected")]
public void SettingElementAtNegativePositionInNoneEmptyDynamicListOfIntsShouldThrowException()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts[-1] = -1;
}
[TestMethod]
public void RemovingElementAtCorrectPositionFromNoneEmptyDynamicListOfIntsShouldReturnCorrectObject()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(0);
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
int startingCount = dynamicListOfInts.Count;
dynamicListOfInts.RemoveAt(1);
bool isRemovedAtPositionCorrect =
dynamicListOfInts[0] == 0 &&
dynamicListOfInts[1] == 2 &&
dynamicListOfInts.Count == startingCount - 1;
Assert.AreEqual(true, isRemovedAtPositionCorrect,
string.Format("The method \"RemoveAt\" does not work correctly!"));
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), "That Exception is not expected")]
public void RemovingElementAtOutOfRangePositionFromNoneEmptyDynamicListOfIntsShouldThrowException()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
dynamicListOfInts.RemoveAt(4);
}
[TestMethod]
[ExpectedException(typeof(ArgumentOutOfRangeException), "That Exception is not expected")]
public void RemovingElementAtNegativePositionFromNoneEmptyDynamicListOfIntsShouldThrowException()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.RemoveAt(-1);
}
[TestMethod]
public void RemovingElementFromNoneEmptyDynamicListOfIntsShouldReturnCorrectObject()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
int startingCount = dynamicListOfInts.Count;
dynamicListOfInts.Remove(2);
bool isRemovedCorrectly =
dynamicListOfInts[0] == 1 &&
dynamicListOfInts[1] == 3 &&
dynamicListOfInts.Count == startingCount - 1;
Assert.AreEqual(true, isRemovedCorrectly,
string.Format("The method \"Remove\" does not work correctly!"));
}
[TestMethod]
public void RemovingNoneExistingElementFromNoneEmptyDynamicListOfIntsShouldReturnMinusOne()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
var returnedValue = dynamicListOfInts.Remove(9);
Assert.AreEqual(-1, returnedValue,
string.Format("The method \"Remove\" does not work correctly when removing none existing number.\nShould return -1!" +
string.Format("returned value is {0}", returnedValue)));
}
[TestMethod]
public void GettingIndexOfElementFromNoneEmptyDynamicListOfIntsShouldReturnCorrectIndex()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
int startingCount = dynamicListOfInts.Count;
bool isIndexOperationSetCorrectly =
dynamicListOfInts[0] == 1 &&
dynamicListOfInts[1] == 2 &&
dynamicListOfInts[2] == 3 &&
dynamicListOfInts.Count == startingCount &&
dynamicListOfInts.IndexOf(3) == 2;
Assert.AreEqual(true, isIndexOperationSetCorrectly,
string.Format("The method \"IndexOf\" does not work correctly!"));
}
[TestMethod]
public void GettingIndexOfNoneExistingElementFromNoneEmptyDynamicListOfIntsShouldReturnMinusOne()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
var returnedValue = dynamicListOfInts.IndexOf(9);
Assert.AreEqual(-1, returnedValue,
string.Format("The method \"IndexOf\" does not work correctly when tring to get none existing number." +
string.Format("\nShould return -1 it returns {0}!", returnedValue)));
}
[TestMethod]
public void ChekingForContainsElementInNoneEmptyDynamicListOfIntsShouldReturnTrue()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
int startingCount = dynamicListOfInts.Count;
bool isContainedCorrectly =
dynamicListOfInts[0] == 1 &&
dynamicListOfInts[1] == 2 &&
dynamicListOfInts[2] == 3 &&
dynamicListOfInts.Count == startingCount &&
dynamicListOfInts.Contains(2);
Assert.AreEqual(true, isContainedCorrectly,
string.Format("The method \"Contains\" does not work correctly!" +
string.Format("\n should return {0} it returns {1}", true, isContainedCorrectly)));
}
[TestMethod]
public void ChekingForContainsNoneExistingElementInNoneEmptyDynamicListOfIntsShouldReturnTrue()
{
var dynamicListOfInts = new DynamicList<int>();
dynamicListOfInts.Add(1);
dynamicListOfInts.Add(2);
dynamicListOfInts.Add(3);
int startingCount = dynamicListOfInts.Count;
bool isContainedCorrectly =
dynamicListOfInts[0] == 1 &&
dynamicListOfInts[1] == 2 &&
dynamicListOfInts[2] == 3 &&
dynamicListOfInts.Count == startingCount &&
dynamicListOfInts.Contains(8);
Assert.AreEqual(false, isContainedCorrectly,
string.Format("The method \"Contains\" does not work correctly!" +
string.Format("\n should return {0} it returns {1}", false, isContainedCorrectly)));
}
}
}