MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / test

Function test

code/other/stable_marriage.test.cpp:2–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1
2void test() {
3 /* Field testing: SPOJ STABLEMP */
4
5 int ts = 100,
6 maxn = 300;
7
8 int **m = new int*[maxn],
9 **w = new int*[maxn],
10 **minv = new int*[maxn],
11 **winv = new int*[maxn];
12
13 for (int i = 0; i < maxn; i++) {
14 m[i] = new int[maxn];
15 w[i] = new int[maxn];
16 minv[i] = new int[maxn];
17 winv[i] = new int[maxn];
18 }
19
20 for (int t = 0; t < ts; t++) {
21
22 int n = rng() % maxn;
23
24 for (int i = 0; i < n; i++) {
25 for (int j = 0; j < n; j++) {
26 m[i][j] = w[i][j] = j;
27 }
28
29 shuffle(m[i], m[i] + n, rng);
30 shuffle(w[i], w[i] + n, rng);
31
32 for (int j = 0; j < n; j++) {
33 minv[i][m[i][j]] = j;
34 winv[i][w[i][j]] = j;
35 }
36 }
37
38 vi res = stable_marriage(n, m, w);
39 vi rev(n, -1);
40
41 for (int i = 0; i < n; i++) {
42 assert_equal(-1, rev[res[i]]);
43 rev[res[i]] = i;
44 }
45
46 for (int i = 0; i < n; i++) {
47 for (int j = 0; j < n; j++) {
48 if (i == j) continue;
49 assert_true( minv[i][res[i]] < minv[i][res[j]] || winv[res[j]][j] < winv[res[j]][i] );
50 }
51 }
52 }
53}
54
55// vim: cc=60 ts=2 sts=2 sw=2:

Callers

nothing calls this directly

Calls 3

stable_marriageFunction · 0.85
assert_trueFunction · 0.85
assert_equalFunction · 0.50

Tested by

no test coverage detected