source: src/test/java/negotiator/protocol/AlternatingMajorityConsensusProtocolTest.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.6 KB
Line 
1package negotiator.protocol;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.mockito.Mockito.when;
6
7import java.util.ArrayList;
8import java.util.List;
9
10import org.junit.Test;
11
12import genius.core.actions.Action;
13import genius.core.actions.Offer;
14import genius.core.protocol.AlternatingMajorityConsensusProtocol;
15import genius.core.protocol.AlternatingMultipleOffersProtocol;
16import genius.core.session.Round;
17
18public 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}
Note: See TracBrowser for help on using the repository browser.