-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLongestPathInADirectedAcyclicGraphTests.cs
More file actions
162 lines (151 loc) · 4.66 KB
/
LongestPathInADirectedAcyclicGraphTests.cs
File metadata and controls
162 lines (151 loc) · 4.66 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
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
using System.Collections.Generic;
using AlgorithmsAndDataStructures.Algorithms.Graph.Common;
using AlgorithmsAndDataStructures.Algorithms.Graph.LongestPath;
using Xunit;
namespace AlgorithmsAndDataStructures.Tests.Algorithm.Graph.LongestPath;
public class LongestPathInADirectedAcyclicGraphTests
{
[Fact]
public void LongestDistanceInOneVerticeGraphIsZero()
{
var sut = new LongestPathInADirectedAcyclicGraph();
var graph = new[]
{
new WeightedGraphVertex()
};
Assert.Collection(sut.GetLongestPath(graph), arg => Assert.Equal(0, arg));
}
[Fact]
public void LongestDistanceTwoVerticesGraph()
{
var sut = new LongestPathInADirectedAcyclicGraph();
var graph = new[]
{
new WeightedGraphVertex
{
Edges = new List<WeightedGraphNodeEdge>
{
new()
{
From = 0,
To = 1,
Weight = 10
}
}
},
new WeightedGraphVertex()
};
#pragma warning disable HAA0101 // Array allocation for params parameter
Assert.Collection(sut.GetLongestPath(graph), arg => Assert.Equal(0, arg), arg => Assert.Equal(10, arg));
#pragma warning restore HAA0101 // Array allocation for params parameter
}
[Fact]
public void Baseline()
{
var sut = new LongestPathInADirectedAcyclicGraph();
var graph = new[]
{
new WeightedGraphVertex
{
Edges = new List<WeightedGraphNodeEdge>
{
new()
{
From = 0,
To = 1,
Weight = 5
},
new()
{
From = 0,
To = 2,
Weight = 3
}
}
},
new WeightedGraphVertex
{
Edges = new List<WeightedGraphNodeEdge>
{
new()
{
From = 1,
To = 3,
Weight = 6
},
new()
{
From = 1,
To = 2,
Weight = 2
}
}
},
new WeightedGraphVertex
{
Edges = new List<WeightedGraphNodeEdge>
{
new()
{
From = 2,
To = 4,
Weight = 4
},
new()
{
From = 2,
To = 5,
Weight = 2
},
new()
{
From = 2,
To = 3,
Weight = 7
}
}
},
new WeightedGraphVertex
{
Edges = new List<WeightedGraphNodeEdge>
{
new()
{
From = 3,
To = 5,
Weight = 1
},
new()
{
From = 3,
To = 4,
Weight = -1
}
}
},
new WeightedGraphVertex
{
Edges = new List<WeightedGraphNodeEdge>
{
new()
{
From = 4,
To = 5,
Weight = 2
}
}
},
new WeightedGraphVertex()
};
var collection = sut.GetLongestPath(graph);
#pragma warning disable HAA0101 // Array allocation for params parameter
Assert.Collection(collection,
arg => Assert.Equal(0, arg),
arg => Assert.Equal(5, arg),
arg => Assert.Equal(7, arg),
arg => Assert.Equal(14, arg),
arg => Assert.Equal(13, arg),
arg => Assert.Equal(15, arg));
#pragma warning restore HAA0101 // Array allocation for params parameter
}
}