-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathperfect-matching-tests.cpp
More file actions
209 lines (169 loc) · 5.36 KB
/
perfect-matching-tests.cpp
File metadata and controls
209 lines (169 loc) · 5.36 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
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
#include "catch.hpp"
#include "perfect-matching.hpp"
#include "graph.hpp"
#include <iostream>
using namespace csce;
using namespace std;
/*
SCENARIO("Getting rank") {
GIVEN("A bipartite graph and subsets") {
Graph e;
e.add(0,2).add(0,3)
.add(1,2).add(1,3);
Graph s1; Graph s2; Graph s3;
s1.add(0,3);
s2.add(0,2).add(1,3);
s3.add(0,2).add(1,2).add(0,3);
PerfectMatching alg;
WHEN("when getting a rank") {
auto rank = alg.getRank(e, s1);
THEN("the rank is 1") {
REQUIRE(rank == 1);
}
}
WHEN("when getting a rank") {
auto rank = alg.getRank(e, s2);
THEN("the rank is 2") {
REQUIRE(rank == 2);
}
}
WHEN("when getting a rank") {
auto rank = alg.getRank(e, s3);
THEN("the rank is 2") {
REQUIRE(rank == 2);
}
}
}
}
SCENARIO("Random number generator") {
GIVEN("A graph with 6 edges") {
Graph graph;
graph.add(0,1).add(1,2).add(2,3).add(3,4).add(4,5).add(5,6);
PerfectMatching alg;
WHEN("requesting a random number") {
auto num = alg.getRandomNumber(graph);
THEN("the naumber is in the acceptable range") {
REQUIRE(num >= 1);
REQUIRE(num <= 5);
}
}
}
}
SCENARIO("Random edges") {
GIVEN("A graph with 6 edges") {
Graph graph;
graph.add(0,1).add(1,2).add(2,3).add(3,4).add(4,5).add(5,6);
PerfectMatching alg;
WHEN("when getting a subset") {
auto subGraph = alg.getRandomSubset(graph);
THEN("the naumber is in the acceptable range") {
REQUIRE(subGraph.getEdgeCount() >= 1);
REQUIRE(subGraph.getEdgeCount() <= 5);
}
}
}
}
SCENARIO("Find obvious matches") {
GIVEN("A graph with obvious matching edges and redundant edges") {
Graph graph;
graph.add(0,1).add(2,3).add(4,5).add(5,6).add(6,7).add(7,4);
PerfectMatching alg;
WHEN("when getting definite matches") {
auto matches = alg.getObviousMatches(graph);
THEN("there are the correct number of matching edges") {
REQUIRE(matches.getEdgeCount() == 2);
}
THEN("0-1 is a match") {
REQUIRE(matches.contains(0,1));
}
THEN("2-3 is a match") {
REQUIRE(matches.contains(2,3));
}
}
}
}
SCENARIO("Finding redundant edges") {
GIVEN("A graph with obvious matching edges and redundant edges") {
Graph e;
e.add(0,2).add(0,3)
.add(1,2).add(1,3);
PerfectMatching alg;
WHEN("when finding redundant edges") {
auto redundant = alg.getRedundantEdges(e);
}
}
}
SCENARIO("Finding a matching (not necessarily a perfect matching)") {
GIVEN("A sparse bipartite graph") {
Graph graph;
graph.add(0,2).add(1,2).add(3);
PerfectMatching alg;
WHEN("when finding redundant edges") {
auto matching = alg.findMatching(graph);
THEN("There are 3 matches") {
REQUIRE(matching.getEdgeCount() == 2);
}
}
}
GIVEN("A non sparse bipartite graph") {
Graph graph;
graph.add(0,2).add(0,3).add(1,2).add(1,3);
PerfectMatching alg;
WHEN("when finding redundant edges") {
auto matching = alg.findMatching(graph);
THEN("There are 2 matches") {
REQUIRE(matching.getEdgeCount() == 2);
}
}
}
}
SCENARIO("Determining perfect matching") {
GIVEN("A bipartite graph and a perfect matching") {
Graph graph;
Graph perfectMatching;
graph.add(0,1).add(2,3).add(0,3);
perfectMatching.add(0,1).add(2,3);
PerfectMatching alg;
WHEN("when tested") {
bool isPerfectMatching = alg.isPerfectMatching(graph, perfectMatching);
THEN("the matching is perfect") {
REQUIRE(isPerfectMatching);
}
}
}
GIVEN("A bipartite graph and an imperfect matching") {
Graph graph;
Graph perfectMatching;
graph.add(0,1).add(2,3).add(0,3);
perfectMatching.add(0,1).add(2,3).add(0,3);
PerfectMatching alg;
WHEN("when tested") {
bool isPerfectMatching = alg.isPerfectMatching(graph, perfectMatching);
THEN("the matching is perfect") {
REQUIRE(!isPerfectMatching);
}
}
}
}
*/
SCENARIO("Find perfect matching") {
GIVEN("A bipartite graph") {
Graph bipartite;
bipartite.add(0,4).add(0,5).add(0,6).add(0,7)
.add(1,4).add(1,5).add(1,6).add(1,7)
.add(2,4).add(2,5).add(2,6).add(2,7)
.add(3,4).add(3,5).add(3,6).add(3,7);
/*
Graph bipartite;
bipartite.add(0,2).add(0,3)
.add(1,2).add(1,3);
*/
PerfectMatching alg;
WHEN("when finding the perfect matching") {
auto perfectMatching = alg.findPerfectMatching(bipartite);
THEN("it halts...") {
//REQUIRE(perfectMatching.getEdgeCount() == 4);
}
}
}
}