source: protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsStateTest.java@ 34

Last change on this file since 34 was 34, checked in by bart, 3 years ago

Added SAOP and simplerunner to GeniusWebPython. Several minor fixes.

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