Changeset 22 for voting/src/test


Ignore:
Timestamp:
09/22/20 16:26:36 (4 years ago)
Author:
bart
Message:

Minor fixes

Location:
voting/src/test/java/geniusweb/voting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • voting/src/test/java/geniusweb/voting/CollectedVotesTest.java

    r21 r22  
    22
    33import static org.junit.Assert.assertEquals;
     4import static org.junit.Assert.assertTrue;
    45import static org.mockito.Mockito.mock;
    56
     
    3536        private final PartyId partyQ = new PartyId("partyQ");
    3637        private final PartyId partyR = new PartyId("partyR");
    37 
    38         private final Vote votePA2 = new Vote(partyP, bidA, 2);
    39         private final Vote voteQA2 = new Vote(partyQ, bidA, 2);
    40         private final Vote voteQB3 = new Vote(partyQ, bidB, 3);
    41         private final Vote voteQB2 = new Vote(partyQ, bidB, 2);
    42         private final Vote voteRA2 = new Vote(partyR, bidA, 2);
    43         private final Vote voteRA3 = new Vote(partyR, bidA, 3);
    44         private final Vote voteRA4 = new Vote(partyR, bidA, 4);
    45         private final Vote voteRB2 = new Vote(partyR, bidB, 2);
     38        private final PartyId partyS = new PartyId("partyS");
     39
     40        private final Vote votePA2 = new Vote(partyP, bidA, 2, 9);
     41        private final Vote voteQA2 = new Vote(partyQ, bidA, 2, 9);
     42        private final Vote voteQB3 = new Vote(partyQ, bidB, 3, 9);
     43        private final Vote voteQB2 = new Vote(partyQ, bidB, 2, 9);
     44        private final Vote voteRA2 = new Vote(partyR, bidA, 2, 9);
     45        private final Vote voteRA3 = new Vote(partyR, bidA, 3, 9);
     46        private final Vote voteRA4 = new Vote(partyR, bidA, 4, 9);
     47        private final Vote voteRB2 = new Vote(partyR, bidB, 2, 9);
    4648
    4749        private Map<PartyId, Integer> allpowers = new HashMap<>();
     
    7375                allpowers.put(partyQ, 1);
    7476                allpowers.put(partyR, 1);
     77                allpowers.put(partyS, 1);
    7578        }
    7679
     
    156159                                allpowers);
    157160
    158                 Set<Set<PartyId>> consensus = cv
    159                                 .getConsensusGroups(Arrays.asList(votePA2, voteQA2));
     161                Set<Set<PartyId>> consensus = cv.getConsensusGroups(
     162                                new HashSet<>(Arrays.asList(votePA2, voteQA2)));
    160163                // should give 1 solution: both parties join in.
    161164                System.out.println(consensus);
     
    169172                                allpowers);
    170173
    171                 Set<Set<PartyId>> consensus = cv
    172                                 .getConsensusGroups(Arrays.asList(votePA2, voteQA2, voteRA4));
     174                Set<Set<PartyId>> consensus = cv.getConsensusGroups(
     175                                new HashSet<>(Arrays.asList(votePA2, voteQA2, voteRA4)));
    173176                // should give 1 solution: P and Q join in. 4 is unreachable.
    174177                System.out.println(consensus);
     
    182185                                allpowers);
    183186
    184                 Set<Set<PartyId>> consensus = cv
    185                                 .getConsensusGroups(Arrays.asList(votePA2, voteQA2, voteRA2));
     187                Set<Set<PartyId>> consensus = cv.getConsensusGroups(
     188                                new HashSet<>(Arrays.asList(votePA2, voteQA2, voteRA2)));
    186189                // should give 4 solutions: P+Q, P+R, Q+R and P+Q+R
    187190                System.out.println(consensus);
     
    200203                                allpowers);
    201204
    202                 Set<Set<PartyId>> consensus = cv
    203                                 .getConsensusGroups(Arrays.asList(votePA2, voteQA2, voteRA4));
     205                Set<Set<PartyId>> consensus = cv.getConsensusGroups(
     206                                new HashSet<>(Arrays.asList(votePA2, voteQA2, voteRA4)));
    204207                // should give solutions P+Q and P+Q+R
    205208                System.out.println(consensus);
     
    244247        }
    245248
     249        @Test
     250        public void getConsensusGroupMaxPower() {
     251                Vote P = new Vote(partyP, bidA, 2, 3);
     252                Vote Q = new Vote(partyQ, bidA, 2, 3);
     253                Vote R = new Vote(partyR, bidA, 2, 3);
     254                Vote S = new Vote(partyS, bidA, 2, 3);
     255                Map<PartyId, Votes> allvotes = new HashMap<>();
     256                allvotes.put(partyP, new Votes(partyP, Arrays.asList(P)));
     257                allvotes.put(partyQ, new Votes(partyQ, Arrays.asList(Q)));
     258                allvotes.put(partyR, new Votes(partyR, Arrays.asList(R)));
     259                allvotes.put(partyS, new Votes(partyS, Arrays.asList(S)));
     260
     261                CollectedVotes cv = new CollectedVotes(allvotes, allpowers);
     262                Set<Set<PartyId>> consensus = cv.getConsensusGroups(
     263                                new HashSet<Vote>(Arrays.asList(P, Q, R, S)));
     264                System.out.println(consensus);
     265                // check that all are size 2 or 3.
     266                for (Set<PartyId> set : consensus) {
     267                        assertTrue(set.size() == 2 || set.size() == 3);
     268                }
     269
     270        }
     271
     272        @Test
     273        public void getConsensusGroupMaxPowerModifiedPartyPowers() {
     274                // party R gets power 2.
     275                Vote P = new Vote(partyP, bidA, 2, 3);
     276                Vote Q = new Vote(partyQ, bidA, 2, 3);
     277                Vote R = new Vote(partyR, bidA, 2, 3);
     278                Map<PartyId, Votes> allvotes = new HashMap<>();
     279                allvotes.put(partyP, new Votes(partyP, Arrays.asList(P)));
     280                allvotes.put(partyQ, new Votes(partyQ, Arrays.asList(Q)));
     281                allvotes.put(partyR, new Votes(partyR, Arrays.asList(R)));
     282
     283                Map<PartyId, Integer> powers = new HashMap<PartyId, Integer>();
     284                powers.put(partyP, 1);
     285                powers.put(partyQ, 1);
     286                powers.put(partyR, 2);
     287
     288                CollectedVotes cv = new CollectedVotes(allvotes, powers);
     289                Set<Set<PartyId>> consensus = cv
     290                                .getConsensusGroups(new HashSet<Vote>(Arrays.asList(P, Q, R)));
     291                System.out.println(consensus);
     292                // R has power 2 now. That means groups of size 3 are not posisble.
     293                // check that all are size 2.
     294                for (Set<PartyId> set : consensus) {
     295                        assertTrue(set.size() == 2);
     296                }
     297
     298        }
     299
    246300}
  • voting/src/test/java/geniusweb/voting/votingevaluators/LargestAgreementsLoopTest.java

    r21 r22  
    7474        @Test
    7575        public void testCollectVotes() {
    76                 Votes vote1AB = new Votes(party1,
    77                                 Arrays.asList(new Vote(party1, a, 2), new Vote(party1, b, 2)));
    78                 Votes vote2AB = new Votes(party2,
    79                                 Arrays.asList(new Vote(party2, a, 2), new Vote(party2, b, 2)));
    80                 Votes vote3C = new Votes(party3, Arrays.asList(new Vote(party3, c, 2)));
    81                 Votes vote4AC = new Votes(party4,
    82                                 Arrays.asList(new Vote(party4, a, 2), new Vote(party4, c, 2)));
     76                Votes vote1AB = new Votes(party1, Arrays
     77                                .asList(new Vote(party1, a, 2, 9), new Vote(party1, b, 2, 9)));
     78                Votes vote2AB = new Votes(party2, Arrays
     79                                .asList(new Vote(party2, a, 2, 9), new Vote(party2, b, 2, 9)));
     80                Votes vote3C = new Votes(party3,
     81                                Arrays.asList(new Vote(party3, c, 2, 9)));
     82                Votes vote4AC = new Votes(party4, Arrays
     83                                .asList(new Vote(party4, a, 2, 9), new Vote(party4, c, 2, 9)));
    8384                // party 1,2,4 vote for A, party 1,2 vote for B, party 3,4 vote for C.
    8485                // the biggest vote is P,Q,S
Note: See TracChangeset for help on using the changeset viewer.