-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathGaleShapleyTest.java
72 lines (54 loc) · 2.53 KB
/
GaleShapleyTest.java
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
package com.thealgorithms.greedyalgorithms;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
public class GaleShapleyTest {
@Test
public void testStableMatch() {
Map<String, LinkedList<String>> womenPrefs = new HashMap<>();
womenPrefs.put("A", new LinkedList<>(List.of("X", "Y", "Z")));
womenPrefs.put("B", new LinkedList<>(List.of("Y", "X", "Z")));
womenPrefs.put("C", new LinkedList<>(List.of("X", "Y", "Z")));
Map<String, LinkedList<String>> menPrefs = new HashMap<>();
menPrefs.put("X", new LinkedList<>(List.of("A", "B", "C")));
menPrefs.put("Y", new LinkedList<>(List.of("B", "A", "C")));
menPrefs.put("Z", new LinkedList<>(List.of("A", "B", "C")));
Map<String, String> result = GaleShapley.stableMatch(womenPrefs, menPrefs);
Map<String, String> expected = new HashMap<>();
expected.put("A", "X");
expected.put("B", "Y");
expected.put("C", "Z");
assertEquals(expected, result);
}
@Test
public void testSinglePair() {
Map<String, LinkedList<String>> womenPrefs = new HashMap<>();
womenPrefs.put("A", new LinkedList<>(List.of("X")));
Map<String, LinkedList<String>> menPrefs = new HashMap<>();
menPrefs.put("X", new LinkedList<>(List.of("A")));
Map<String, String> result = GaleShapley.stableMatch(womenPrefs, menPrefs);
Map<String, String> expected = new HashMap<>();
expected.put("A", "X");
assertEquals(expected, result);
}
@Test
public void testEqualPreferences() {
Map<String, LinkedList<String>> womenPrefs = new HashMap<>();
womenPrefs.put("A", new LinkedList<>(List.of("X", "Y", "Z")));
womenPrefs.put("B", new LinkedList<>(List.of("X", "Y", "Z")));
womenPrefs.put("C", new LinkedList<>(List.of("X", "Y", "Z")));
Map<String, LinkedList<String>> menPrefs = new HashMap<>();
menPrefs.put("X", new LinkedList<>(List.of("A", "B", "C")));
menPrefs.put("Y", new LinkedList<>(List.of("A", "B", "C")));
menPrefs.put("Z", new LinkedList<>(List.of("A", "B", "C")));
Map<String, String> result = GaleShapley.stableMatch(womenPrefs, menPrefs);
Map<String, String> expected = new HashMap<>();
expected.put("A", "X");
expected.put("B", "Y");
expected.put("C", "Z");
assertEquals(expected, result);
}
}