1 | package geniusweb.protocol.tournament.allpermutationslearn;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 | import static org.mockito.Mockito.mock;
|
---|
7 | import static org.mockito.Mockito.when;
|
---|
8 |
|
---|
9 | import java.math.BigInteger;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.Arrays;
|
---|
12 | import java.util.List;
|
---|
13 | import java.util.Map;
|
---|
14 |
|
---|
15 | import org.junit.Before;
|
---|
16 | import org.junit.Test;
|
---|
17 |
|
---|
18 | import geniusweb.actions.PartyId;
|
---|
19 | import geniusweb.protocol.session.SessionResult;
|
---|
20 | import geniusweb.protocol.session.SessionSettings;
|
---|
21 | import geniusweb.references.PartyWithProfile;
|
---|
22 | import tudelft.utilities.immutablelist.ImmutableList;
|
---|
23 |
|
---|
24 | public class AllPermutationsLearnStateTest {
|
---|
25 |
|
---|
26 | private final AllPermutationsLearnSettings toursettings = mock(
|
---|
27 | AllPermutationsLearnSettings.class);;
|
---|
28 | @SuppressWarnings("unchecked")
|
---|
29 | private final List<SessionResult> results = mock(List.class);
|
---|
30 | @SuppressWarnings("unchecked")
|
---|
31 | private final ImmutableList<SessionSettings> sesettings = mock(
|
---|
32 | ImmutableList.class);
|
---|
33 | private final AllPermutationsLearnState state = new AllPermutationsLearnState(
|
---|
34 | toursettings, results);
|
---|
35 | private final SessionSettings session7settings = mock(
|
---|
36 | SessionSettings.class);
|
---|
37 | private final long NOW = 1000;
|
---|
38 | private PartyWithProfile pp1 = mock(PartyWithProfile.class);
|
---|
39 | private PartyWithProfile pp2 = mock(PartyWithProfile.class);
|
---|
40 |
|
---|
41 | @SuppressWarnings("unchecked")
|
---|
42 | private final List<PartyWithProfile> participants = Arrays.asList(pp1, pp2);
|
---|
43 |
|
---|
44 | @Before
|
---|
45 | public void before() {
|
---|
46 | when(toursettings.permutations()).thenReturn(sesettings);
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Test
|
---|
50 | public void getResultsTest() {
|
---|
51 | assertEquals(results, state.getResults());
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Test
|
---|
55 | public void isFinalTestFalse() {
|
---|
56 | when(sesettings.size()).thenReturn(BigInteger.TEN);
|
---|
57 | when(results.size()).thenReturn(7);
|
---|
58 | assertFalse(state.isFinal(NOW));
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test
|
---|
62 | public void isFinalTestTrue() {
|
---|
63 | when(sesettings.size()).thenReturn(BigInteger.TEN);
|
---|
64 | when(results.size()).thenReturn(10);
|
---|
65 | assertTrue(state.isFinal(NOW));
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Test
|
---|
69 | public void getNextSetting() {
|
---|
70 | prepareNextSettings();
|
---|
71 | assertEquals(session7settings, state.getNextSettings());
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void prepareNextSettings() {
|
---|
75 | when(results.size()).thenReturn(7); // result 0..6
|
---|
76 | when(sesettings.size()).thenReturn(BigInteger.TEN);
|
---|
77 | // when(session7settings.getTeams()).thenReturn(participants);
|
---|
78 | when(session7settings.getAllParties()).thenReturn(participants);
|
---|
79 | when(sesettings.get(BigInteger.valueOf(7)))
|
---|
80 | .thenReturn(session7settings);
|
---|
81 |
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Test
|
---|
85 | public void withTest() {
|
---|
86 | prepareNextSettings();
|
---|
87 | ArrayList<SessionResult> results1 = new ArrayList<>();
|
---|
88 | for (int n = 0; n < 7; n++) {
|
---|
89 | results1.add(mock(SessionResult.class));
|
---|
90 | }
|
---|
91 | // use state with "real" results... to allow array copy in with
|
---|
92 | AllPermutationsLearnState state0 = new AllPermutationsLearnState(
|
---|
93 | toursettings, results1);
|
---|
94 |
|
---|
95 | when(sesettings.size()).thenReturn(BigInteger.TEN);
|
---|
96 | when(sesettings.get(BigInteger.valueOf(7)))
|
---|
97 | .thenReturn(session7settings);
|
---|
98 |
|
---|
99 | SessionResult result = mock(SessionResult.class);
|
---|
100 |
|
---|
101 | Map<PartyId, PartyWithProfile> participants3 = mock(Map.class);
|
---|
102 | when(participants3.values()).thenReturn(participants);
|
---|
103 | when(result.getParticipants()).thenReturn(participants3);
|
---|
104 | AllPermutationsLearnState state1 = state0.with(Arrays.asList(result));
|
---|
105 |
|
---|
106 | assertEquals(8, state1.getResults().size());
|
---|
107 | assertEquals(toursettings, state1.getSettings());
|
---|
108 |
|
---|
109 | }
|
---|
110 | }
|
---|