-
Notifications
You must be signed in to change notification settings - Fork 1
/
DoublyLinkedListTests.cs
110 lines (93 loc) · 3.21 KB
/
DoublyLinkedListTests.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
using AlgorithmsAndDataStructures.DataStructures.Common;
using AlgorithmsAndDataStructures.DataStructures.LinkedList;
using System.Linq;
using Xunit;
namespace AlgorithmsAndDataStructures.Tests.DataStructures.LinkedList
{
public class DoublyLinkedListTests
{
[Fact]
public void PrependToEmptyDoesntThrowAnError()
{
var sut = new DoublyLinkedList<int>();
sut.Prepend(1);
Assert.Single(sut.Traverse());
}
[Fact]
public void AppendToEmptyDoesntThrowAnError()
{
var sut = new DoublyLinkedList<int>();
sut.Append(1);
Assert.Single(sut.Traverse());
}
[Fact]
public void RemoveByPositionFromEmptyListDoesntThrowAnError()
{
var sut = new DoublyLinkedList<int>();
sut.RemoveByPosition(1);
}
[Fact]
public void RemoveByPositionOutsideOfBoundariesDoesntThrowAnError()
{
var sut = new DoublyLinkedList<int>(new DoublyNode<int> { Value = 1 });
sut.RemoveByPosition(1);
Assert.Single(sut.Traverse());
}
[Fact]
public void RemoveByPositionOutsideOfBoundariesDoesntRemoveNodes()
{
var sut = new DoublyLinkedList<int>(new DoublyNode<int> { Value = 1 });
sut.Append(2);
sut.Append(3);
sut.RemoveByPosition(int.MaxValue);
Assert.Equal(3, sut.Traverse().Count);
}
[Fact]
public void RemoveByMiddlePosition()
{
var sut = new DoublyLinkedList<int>(new DoublyNode<int> { Value = 1 });
sut.Append(2);
sut.Append(3);
sut.RemoveByPosition(1);
Assert.Equal(2, sut.Traverse().Count);
Assert.Equal(1, sut.Traverse().First());
Assert.Equal(3, sut.Traverse().Skip(1).First());
}
[Fact]
public void RemoveByStartingPosition()
{
var sut = new DoublyLinkedList<int>(new DoublyNode<int> { Value = 1 });
sut.Append(2);
sut.Append(3);
sut.RemoveByPosition(0);
Assert.Equal(2, sut.Traverse().Count);
Assert.Equal(2, sut.Traverse().First());
Assert.Equal(3, sut.Traverse().Skip(1).First());
}
[Fact]
public void RemoveByEndPosition()
{
var sut = new DoublyLinkedList<int>(new DoublyNode<int> { Value = 1 });
sut.Append(2);
sut.Append(3);
sut.RemoveByPosition(2);
Assert.Equal(2, sut.Traverse().Count);
Assert.Equal(1, sut.Traverse().First());
Assert.Equal(2, sut.Traverse().Skip(1).First());
}
[Fact]
public void Reverse()
{
var sut = new DoublyLinkedList<int>(new DoublyNode<int> { Value = 1 });
sut.Append(2);
sut.Append(3);
var traversed = sut.Traverse();
sut.Reverse();
var traverseReverted = sut.Traverse();
for (var i = 0; i < traversed.Count; i++)
{
Assert.Equal(traversed[i], traverseReverted[traverseReverted.Count - i - 1]);
}
}
}
}