-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestUtil.java
More file actions
54 lines (50 loc) · 1.75 KB
/
TestUtil.java
File metadata and controls
54 lines (50 loc) · 1.75 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
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
public class TestUtil {
public Picks randomSelection(LinkedList<Person> cOrig, int pairs, boolean isQueer, LinkedList<Match> confirmedMatches){
LinkedList<Person> contestants = new LinkedList<>();
contestants.addAll(cOrig);
Collections.shuffle(contestants);
Match[] m = new Match[pairs];
int i=0;
for(i=0; i< confirmedMatches.size(); i++){
m[i] = confirmedMatches.get(i);
contestants.remove(m[i].getP1());
contestants.remove(m[i].getP2());
}
for( i=i; i<pairs; i++){
if(isQueer){
m[i] = randomPairQueer(contestants);
contestants.remove(m[i].getP1());
contestants.remove(m[i].getP2());
}else{
m[i] = randomPairStraight(contestants);
contestants.remove(m[i].getP1());
contestants.remove(m[i].getP2());
}
}
return new Picks(m);
}
public Match randomPairStraight(LinkedList<Person> contestants){
Collections.shuffle(contestants);
Person m = null;
Person f = null;
int i =0;
while ((m==null || f==null)){
if(m== null && contestants.get(i).isMale()){
m= contestants.get(i);
}else{
if(f==null && !contestants.get(i).isMale()){
f = contestants.get(i);
}
}
i++;
}
return new Match(m,f);
}
public Match randomPairQueer(LinkedList<Person> contestants){
Collections.shuffle(contestants);
return new Match(contestants.get(0), contestants.get(1));
}
}