-
Notifications
You must be signed in to change notification settings - Fork 292
/
ArrayList_Tests.cs
65 lines (53 loc) · 1.85 KB
/
ArrayList_Tests.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
using System;
using System.Linq;
using Advanced.Algorithms.DataStructures.Foundation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.DataStructures
{
[TestClass]
public class ArrayListTests
{
[TestMethod]
public void ArrayList_Test()
{
var arrayList = new ArrayList<int>();
var nodeCount = 1000;
for (var i = 0; i <= nodeCount; i++)
{
arrayList.Add(i);
Assert.AreEqual(true, arrayList.Contains(i));
}
//IEnumerable test using linq
Assert.AreEqual(arrayList.Length, arrayList.Count());
for (var i = 0; i <= nodeCount; i++)
{
arrayList.RemoveAt(0);
Assert.AreEqual(false, arrayList.Contains(i));
}
var rnd = new Random();
var testSeries = Enumerable.Range(1, nodeCount).OrderBy(x => rnd.Next()).ToList();
foreach (var item in testSeries)
{
arrayList.Add(item);
Assert.AreEqual(true, arrayList.Contains(item));
}
for (var i = 1; i <= nodeCount; i++) arrayList.RemoveAt(0);
}
[TestMethod]
public void ArrayList_InsertAt_Test()
{
var arrayList = new ArrayList<int>();
var nodeCount = 10;
for (var i = 0; i <= nodeCount; i++)
{
arrayList.InsertAt(i, i);
Assert.AreEqual(true, arrayList.Contains(i));
}
arrayList.InsertAt(5, 50000);
//IEnumerable test using linq
Assert.AreEqual(arrayList.Length, arrayList.Count());
Assert.AreEqual(true, arrayList.Contains(50000));
Assert.AreEqual(nodeCount + 2, arrayList.Length);
}
}
}