-
Notifications
You must be signed in to change notification settings - Fork 293
/
HopcroftKarp_Tests.cs
150 lines (117 loc) · 4.24 KB
/
HopcroftKarp_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
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
using Advanced.Algorithms.DataStructures.Graph.AdjacencyList;
using Advanced.Algorithms.Graph;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Advanced.Algorithms.Tests.Graph
{
[TestClass]
public class HopcroftKarpTests
{
[TestMethod]
public void HopcroftKarp_AdjacencyListGraph_Smoke_Test()
{
var graph = new Graph<char>();
graph.AddVertex('A');
graph.AddVertex('B');
graph.AddVertex('C');
graph.AddVertex('D');
graph.AddVertex('E');
graph.AddVertex('F');
graph.AddVertex('G');
graph.AddVertex('H');
graph.AddVertex('I');
graph.AddEdge('A', 'F');
graph.AddEdge('B', 'F');
graph.AddEdge('B', 'G');
graph.AddEdge('C', 'H');
graph.AddEdge('C', 'I');
graph.AddEdge('D', 'G');
graph.AddEdge('D', 'H');
graph.AddEdge('E', 'F');
graph.AddEdge('E', 'I');
var algorithm = new HopcroftKarpMatching<char>();
var result = algorithm.GetMaxBiPartiteMatching(graph);
Assert.AreEqual(result.Count, 4);
}
[TestMethod]
public void HopcroftKarp_AdjacencyMatrixGraph_Smoke_Test()
{
var graph = new Algorithms.DataStructures.Graph.AdjacencyMatrix.Graph<char>();
graph.AddVertex('A');
graph.AddVertex('B');
graph.AddVertex('C');
graph.AddVertex('D');
graph.AddVertex('E');
graph.AddVertex('F');
graph.AddVertex('G');
graph.AddVertex('H');
graph.AddVertex('I');
graph.AddEdge('A', 'F');
graph.AddEdge('B', 'F');
graph.AddEdge('B', 'G');
graph.AddEdge('C', 'H');
graph.AddEdge('C', 'I');
graph.AddEdge('D', 'G');
graph.AddEdge('D', 'H');
graph.AddEdge('E', 'F');
graph.AddEdge('E', 'I');
var algorithm = new HopcroftKarpMatching<char>();
var result = algorithm.GetMaxBiPartiteMatching(graph);
Assert.AreEqual(result.Count, 4);
}
[TestMethod]
public void HopcroftKarp_AdjacencyListGraph_Accurancy_Test()
{
var graph = new Graph<char>();
graph.AddVertex('E');
graph.AddVertex('N');
graph.AddVertex('J');
graph.AddVertex('O');
graph.AddVertex('Y');
graph.AddVertex('Z');
graph.AddVertex('1');
graph.AddVertex('2');
graph.AddVertex('3');
graph.AddVertex('4');
graph.AddVertex('5');
graph.AddVertex('6');
graph.AddEdge('E', '1');
graph.AddEdge('N', '4');
graph.AddEdge('J', '1');
graph.AddEdge('J', '2');
graph.AddEdge('J', '4');
graph.AddEdge('O', '2');
graph.AddEdge('O', '3');
graph.AddEdge('Y', '3');
graph.AddEdge('Y', '5');
graph.AddEdge('Z', '4');
graph.AddEdge('Z', '5');
graph.AddEdge('Z', '6');
var algorithm = new HopcroftKarpMatching<char>();
var result = algorithm.GetMaxBiPartiteMatching(graph);
Assert.AreEqual(result.Count, 6);
}
[TestMethod]
public void HopcroftKarp_AdjacencyListGraph_Accurancy_Test_Fully_Connected_Bipartite_Graph()
{
var graph = new Graph<char>();
graph.AddVertex('A');
graph.AddVertex('B');
graph.AddVertex('C');
graph.AddVertex('D');
graph.AddVertex('E');
graph.AddVertex('F');
graph.AddEdge('A', 'D');
graph.AddEdge('A', 'E');
graph.AddEdge('A', 'F');
graph.AddEdge('B', 'D');
graph.AddEdge('B', 'E');
graph.AddEdge('B', 'F');
graph.AddEdge('C', 'D');
graph.AddEdge('C', 'E');
graph.AddEdge('C', 'F');
var algorithm = new HopcroftKarpMatching<char>();
var result = algorithm.GetMaxBiPartiteMatching(graph);
Assert.AreEqual(result.Count, 3);
}
}
}