-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGraphExtensionsTest.cs
248 lines (223 loc) · 23.2 KB
/
GraphExtensionsTest.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
// <copyright file="GraphExtensionsTest.cs" company="Jonathan de Halleux">Copyright http://quickgraph.codeplex.com/</copyright>
using System;
using System.Collections.Generic;
using Microsoft.Pex.Framework;
using Microsoft.Pex.Framework.Validation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickGraph;
using System.Collections.ObjectModel;
using QuickGraph.Tests;
using QuickGraph.Serialization;
using System.Linq;
namespace QuickGraph
{
public class TestVertexType
{
public TestVertexType(string name)
{
this.Name = name;
}
public string Name { get; set; }
}
/// <summary>This class contains parameterized unit tests for GraphExtensions</summary>
[TestClass]
[PexClass(typeof(GraphExtensions))]
[PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
[PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
public partial class GraphExtensionsTest
{
[TestMethod]
public void DictionaryToVertexAndEdgeListGraph()
{
var dic = new Dictionary<int, int[]>();
dic.Add(0, new int[] { 1, 2 });
dic.Add(1, new int[] { 2 });
dic.Add(2, new int[] { });
var graph = dic.ToVertexAndEdgeListGraph(
kv => Array.ConvertAll(kv.Value, v => new SEquatableEdge<int>(kv.Key, v))
);
foreach (var kv in dic)
{
Assert.IsTrue(graph.ContainsVertex(kv.Key));
foreach (var i in kv.Value)
{
Assert.IsTrue(graph.ContainsVertex(i));
Assert.IsTrue(graph.ContainsEdge(kv.Key, i));
}
}
}
[TestMethod]
public void CollectionOfEdgesToAdjacencyGraph()
{
int numVertices = 4;
var vertices = new Collection<TestVertexType>();
for (int i = 0; i < numVertices; i++)
{
vertices.Add(new TestVertexType(i.ToString()));
}
var edges = TestHelper.CreateAllPairwiseEdges(vertices, vertices,
(source, target) => new Edge<TestVertexType>(source, target));
var adjGraph = edges.ToAdjacencyGraph<TestVertexType, Edge<TestVertexType>>();
//Verify that the right number of vertices were created
Assert.AreEqual(numVertices, adjGraph.Vertices.ToList().Count);
}
/// <summary>Test stub for ToAdjacencyGraph(IEnumerable`1<!!1>, Boolean)</summary>
[PexMethod]
public AdjacencyGraph<TVertex, TEdge> ToAdjacencyGraph<TVertex, TEdge>(IEnumerable<TEdge> edges, bool allowParallelEdges)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToAdjacencyGraph(IEnumerable`1<!!1>, Boolean)
AdjacencyGraph<TVertex, TEdge> result
= GraphExtensions.ToAdjacencyGraph<TVertex, TEdge>(edges, allowParallelEdges);
return result;
}
/// <summary>Test stub for ToAdjacencyGraph(IEnumerable`1<!!1>)</summary>
[PexMethod]
public AdjacencyGraph<TVertex, TEdge> ToAdjacencyGraph01<TVertex, TEdge>(IEnumerable<TEdge> edges)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToAdjacencyGraph01(IEnumerable`1<!!1>)
AdjacencyGraph<TVertex, TEdge> result
= GraphExtensions.ToAdjacencyGraph<TVertex, TEdge>(edges);
return result;
}
/// <summary>Test stub for ToAdjacencyGraph(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>, Boolean)</summary>
[PexMethod]
public AdjacencyGraph<TVertex, TEdge> ToAdjacencyGraph02<TVertex, TEdge>(
IEnumerable<TVertex> vertices,
Func<TVertex, IEnumerable<TEdge>> outEdgesFactory,
bool allowParallelEdges
)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToAdjacencyGraph02(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>, Boolean)
AdjacencyGraph<TVertex, TEdge> result
= GraphExtensions.ToAdjacencyGraph<TVertex, TEdge>
(vertices, outEdgesFactory, allowParallelEdges);
return result;
}
/// <summary>Test stub for ToAdjacencyGraph(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>)</summary>
[PexMethod]
public AdjacencyGraph<TVertex, TEdge> ToAdjacencyGraph03<TVertex, TEdge>(
IEnumerable<TVertex> vertices,
Func<TVertex, IEnumerable<TEdge>> outEdgesFactory
)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToAdjacencyGraph03(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>)
AdjacencyGraph<TVertex, TEdge> result
= GraphExtensions.ToAdjacencyGraph<TVertex, TEdge>(vertices, outEdgesFactory);
return result;
}
/// <summary>Test stub for ToAdjacencyGraph(IEnumerable`1<SEquatableEdge`1<!!0>>)</summary>
[PexMethod]
[PexGenericArguments(typeof(int))]
public AdjacencyGraph<TVertex, SEquatableEdge<TVertex>> ToAdjacencyGraph04<TVertex>(IEnumerable<SEquatableEdge<TVertex>> vertexPairs)
{
// TODO: add assertions to method GraphExtensionsTest.ToAdjacencyGraph04(IEnumerable`1<SEquatableEdge`1<!!0>>)
AdjacencyGraph<TVertex, SEquatableEdge<TVertex>> result
= GraphExtensions.ToAdjacencyGraph<TVertex>(vertexPairs);
return result;
}
/// <summary>Test stub for ToBidirectionalGraph(IVertexAndEdgeListGraph`2<!!0,!!1>)</summary>
[PexMethod]
public IBidirectionalGraph<TVertex, TEdge> ToBidirectionalGraph<TVertex, TEdge>(IVertexAndEdgeListGraph<TVertex, TEdge> graph)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToBidirectionalGraph(IVertexAndEdgeListGraph`2<!!0,!!1>)
IBidirectionalGraph<TVertex, TEdge> result
= GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>(graph);
return result;
}
/// <summary>Test stub for ToBidirectionalGraph(IEnumerable`1<!!1>, Boolean)</summary>
[PexMethod]
public BidirectionalGraph<TVertex, TEdge> ToBidirectionalGraph01<TVertex, TEdge>(IEnumerable<TEdge> edges, bool allowParallelEdges)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToBidirectionalGraph01(IEnumerable`1<!!1>, Boolean)
BidirectionalGraph<TVertex, TEdge> result
= GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>
(edges, allowParallelEdges);
return result;
}
/// <summary>Test stub for ToBidirectionalGraph(IEnumerable`1<!!1>)</summary>
[PexMethod]
public BidirectionalGraph<TVertex, TEdge> ToBidirectionalGraph02<TVertex, TEdge>(IEnumerable<TEdge> edges)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToBidirectionalGraph02(IEnumerable`1<!!1>)
BidirectionalGraph<TVertex, TEdge> result
= GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>(edges);
return result;
}
/// <summary>Test stub for ToBidirectionalGraph(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>, Boolean)</summary>
[PexMethod]
public BidirectionalGraph<TVertex, TEdge> ToBidirectionalGraph03<TVertex, TEdge>(
IEnumerable<TVertex> vertices,
Func<TVertex, IEnumerable<TEdge>> outEdgesFactory,
bool allowParallelEdges
)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToBidirectionalGraph03(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>, Boolean)
BidirectionalGraph<TVertex, TEdge> result
= GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>
(vertices, outEdgesFactory, allowParallelEdges);
return result;
}
/// <summary>Test stub for ToBidirectionalGraph(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>)</summary>
[PexMethod]
public BidirectionalGraph<TVertex, TEdge> ToBidirectionalGraph04<TVertex, TEdge>(
IEnumerable<TVertex> vertices,
Func<TVertex, IEnumerable<TEdge>> outEdgesFactory
)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToBidirectionalGraph04(IEnumerable`1<!!0>, Func`2<!!0,IEnumerable`1<!!1>>)
BidirectionalGraph<TVertex, TEdge> result
= GraphExtensions.ToBidirectionalGraph<TVertex, TEdge>
(vertices, outEdgesFactory);
return result;
}
/// <summary>Test stub for ToBidirectionalGraph(IEnumerable`1<SEquatableEdge`1<!!0>>)</summary>
[PexMethod]
[PexGenericArguments(typeof(int))]
public BidirectionalGraph<TVertex, SEquatableEdge<TVertex>> ToBidirectionalGraph05<TVertex>(IEnumerable<SEquatableEdge<TVertex>> vertexPairs)
{
// TODO: add assertions to method GraphExtensionsTest.ToBidirectionalGraph05(IEnumerable`1<SEquatableEdge`1<!!0>>)
BidirectionalGraph<TVertex, SEquatableEdge<TVertex>> result
= GraphExtensions.ToBidirectionalGraph<TVertex>(vertexPairs);
return result;
}
/// <summary>Test stub for ToUndirectedGraph(IEnumerable`1<!!1>)</summary>
[PexMethod]
public UndirectedGraph<TVertex, TEdge> ToUndirectedGraph<TVertex, TEdge>(IEnumerable<TEdge> edges)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToUndirectedGraph(IEnumerable`1<!!1>)
UndirectedGraph<TVertex, TEdge> result
= GraphExtensions.ToUndirectedGraph<TVertex, TEdge>(edges);
return result;
}
/// <summary>Test stub for ToUndirectedGraph(IEnumerable`1<!!1>, Boolean)</summary>
[PexMethod]
public UndirectedGraph<TVertex, TEdge> ToUndirectedGraph01<TVertex, TEdge>(IEnumerable<TEdge> edges, bool allowParralelEdges)
where TEdge : IEdge<TVertex>
{
// TODO: add assertions to method GraphExtensionsTest.ToUndirectedGraph01(IEnumerable`1<!!1>, Boolean)
UndirectedGraph<TVertex, TEdge> result =
GraphExtensions.ToUndirectedGraph<TVertex, TEdge>(edges, allowParralelEdges);
return result;
}
/// <summary>Test stub for ToUndirectedGraph(IEnumerable`1<SEquatableEdge`1<!!0>>)</summary>
[PexMethod]
[PexGenericArguments(typeof(int))]
public UndirectedGraph<TVertex, SEquatableEdge<TVertex>> ToUndirectedGraph02<TVertex>(IEnumerable<SEquatableEdge<TVertex>> vertexPairs)
{
// TODO: add assertions to method GraphExtensionsTest.ToUndirectedGraph02(IEnumerable`1<SEquatableEdge`1<!!0>>)
UndirectedGraph<TVertex, SEquatableEdge<TVertex>> result
= GraphExtensions.ToUndirectedGraph<TVertex>(vertexPairs);
return result;
}
}
}