1 | package negotiator.protocol;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.mockito.Mockito.when;
|
---|
6 |
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.junit.Test;
|
---|
11 |
|
---|
12 | import genius.core.actions.Action;
|
---|
13 | import genius.core.actions.Offer;
|
---|
14 | import genius.core.protocol.AlternatingMajorityConsensusProtocol;
|
---|
15 | import genius.core.protocol.AlternatingMultipleOffersProtocol;
|
---|
16 | import genius.core.session.Round;
|
---|
17 |
|
---|
18 | public class AlternatingMajorityConsensusProtocolTest extends AlternatingMultipleOffersProtocolTest {
|
---|
19 |
|
---|
20 | @Override
|
---|
21 | protected Class<? extends AlternatingMultipleOffersProtocol> getProtocol() {
|
---|
22 | return AlternatingMajorityConsensusProtocol.class;
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | @Test
|
---|
27 | public void testIsNotFinishedWithIncompleteVotes() {
|
---|
28 |
|
---|
29 | // We need at least two rounds for a finish.
|
---|
30 | List<Round> rounds = new ArrayList<Round>();
|
---|
31 |
|
---|
32 | // 3 turns is apparently insufficient. Not clear why.
|
---|
33 | // but protocol.isFinished should not crash on that.
|
---|
34 | Offer firstoffer = offer();
|
---|
35 | Offer secondoffer = offer();
|
---|
36 | rounds.add(mockedRound(new Action[] { firstoffer, secondoffer, offer() }));
|
---|
37 | // incomplete: only votes for bid 1.
|
---|
38 | Round voteRound = mockedRound(new Action[] { REJECT, ACCEPT, ACCEPT });
|
---|
39 | rounds.add(voteRound);
|
---|
40 |
|
---|
41 | when(session.getMostRecentRound()).thenReturn(voteRound);
|
---|
42 | when(session.getRounds()).thenReturn(rounds);
|
---|
43 |
|
---|
44 | // we have round 0 and 1 done
|
---|
45 | when(session.getRoundNumber()).thenReturn(2);
|
---|
46 | when(session.getRounds()).thenReturn(rounds);
|
---|
47 |
|
---|
48 | assertFalse(protocol.isFinished(session, parties));
|
---|
49 | assertEquals(secondoffer.getBid(), protocol.getCurrentAgreement(session, parties));
|
---|
50 | }
|
---|
51 |
|
---|
52 | }
|
---|