Changeset 22 for events


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

Minor fixes

Location:
events
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • events/pom.xml

    r21 r22  
    66        <groupId>geniusweb</groupId>
    77        <artifactId>events</artifactId>
    8         <version>1.5.0</version> <!-- must equal ${geniusweb.version} -->
     8        <version>1.5.1</version> <!-- must equal ${geniusweb.version} -->
    99        <packaging>jar</packaging>
    1010
     
    1717                <passwd>${env.ARTIFACTORY_PASS}</passwd>
    1818                <jackson-2-version>2.9.10</jackson-2-version>
    19                 <geniusweb.version>1.5.0</geniusweb.version>
     19                <geniusweb.version>1.5.1</geniusweb.version>
    2020        </properties>
    2121
  • events/src/main/java/geniusweb/actions/Vote.java

    r21 r22  
    1414public class Vote extends ActionWithBid {
    1515        private final Integer minPower;
     16        private final Integer maxPower;
    1617
    1718        /**
     
    1920         * @param bid      the bid that is voted on
    2021         * @param minPower the minimum power this bid must get in order for the vote
    21          *                 to be valid. If power=1 for all participants (usually the
    22          *                 default) power can be interpreted as number of votes
     22         *                 to be valid. Power is the sum of the powers of the
     23         *                 parties that are in the deal. If power=1 for all
     24         *                 participants (usually the default) power can be
     25         *                 interpreted as number of votes
     26         * @param maxPower the maximum power this bid must get in order for the vote
     27         *                 to be valid. See {@link #minPower}
    2328         */
    2429        @JsonCreator
    2530        public Vote(@JsonProperty("actor") PartyId id, @JsonProperty("bid") Bid bid,
    26                         @JsonProperty("minPower") Integer minPower) {
     31                        @JsonProperty("minPower") Integer minPower,
     32                        @JsonProperty("maxPower") Integer maxPower) {
    2733                super(id, bid);
    2834                this.minPower = minPower;
    29                 if (bid == null || minPower == null || minPower < 1) {
     35                this.maxPower = maxPower;
     36                if (bid == null || minPower == null || minPower < 1 || maxPower == null
     37                                || maxPower < minPower) {
    3038                        throw new IllegalArgumentException(
    31                                         "Vote must have non-null bid and minVotes, and minVotes must be >=1");
     39                                        "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower");
    3240                }
    3341        }
     
    3543        /**
    3644         *
    37          * @return the minimum number of votes this bid must get in order for the
    38          *         vote to be valid.
     45         * @return the minimum power this bid must get in order for the vote to be
     46         *         valid.
    3947         */
    4048        public Integer getMinPower() {
     
    4250        }
    4351
     52        /**
     53         *
     54         * @return the max power this bid must get in order for the vote to be
     55         *         valid.
     56         */
     57
     58        public Integer getMaxPower() {
     59                return maxPower;
     60        }
     61
    4462        @Override
    4563        public String toString() {
    46                 return "Vote[" + getActor() + "," + getBid() + "," + minPower + "]";
     64                return "Vote[" + getActor() + "," + getBid() + "," + minPower + ","
     65                                + maxPower + "]";
    4766        }
    4867
     
    5170                final int prime = 31;
    5271                int result = super.hashCode();
     72                result = prime * result
     73                                + ((maxPower == null) ? 0 : maxPower.hashCode());
    5374                result = prime * result
    5475                                + ((minPower == null) ? 0 : minPower.hashCode());
     
    6586                        return false;
    6687                Vote other = (Vote) obj;
     88                if (maxPower == null) {
     89                        if (other.maxPower != null)
     90                                return false;
     91                } else if (!maxPower.equals(other.maxPower))
     92                        return false;
    6793                if (minPower == null) {
    6894                        if (other.minPower != null)
  • events/src/test/java/actions/PartyIdTest.java

    r1 r22  
    2626        }
    2727
     28        @SuppressWarnings("unused")
    2829        @Test(expected = IllegalArgumentException.class)
    2930        public void testRestrictions() {
     
    3132        }
    3233
     34        @SuppressWarnings("unused")
    3335        @Test(expected = IllegalArgumentException.class)
    3436        public void testRestrictions2() {
     
    3638        }
    3739
     40        @SuppressWarnings("unused")
    3841        @Test(expected = IllegalArgumentException.class)
    3942        public void testRestrictions3() {
     
    4144        }
    4245
     46        @SuppressWarnings("unused")
    4347        @Test(expected = IllegalArgumentException.class)
    4448        public void testRestrictions4() {
     
    4650        }
    4751
     52        @SuppressWarnings("unused")
    4853        @Test(expected = IllegalArgumentException.class)
    4954        public void testRestrictions5() {
     
    5661        }
    5762
     63        @SuppressWarnings("unused")
    5864        @Test
    5965        public void testRestrictions6() {
     
    6167        }
    6268
     69        @SuppressWarnings("unused")
    6370        @Test
    6471        public void testRestrictions7() {
  • events/src/test/java/actions/PartyIdTest1.java

    r1 r22  
    4343        }
    4444
     45        @SuppressWarnings("unused")
    4546        @Test(expected = IllegalArgumentException.class)
    4647        public void smokeTest() throws URISyntaxException {
     
    4849        }
    4950
     51        @SuppressWarnings("unused")
    5052        @Test(expected = IllegalArgumentException.class)
    5153        public void nullTest() throws URISyntaxException {
  • events/src/test/java/actions/VoteTest.java

    r21 r22  
    66import java.util.Arrays;
    77import java.util.HashMap;
    8 import java.util.LinkedList;
    98import java.util.List;
    109import java.util.Map;
     
    3938        private final static Value VALUE2 = new NumberValue("10");
    4039        // issue 2 is NUMBER and thus serializes with leading '='
    41         private final String votestring = "{\"vote\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"minPower\":1}}";
     40        private final String votestring = "{\"vote\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"issue2\":10,\"issue1\":\"value1\"}},\"minPower\":1,\"maxPower\":2}}";
    4241
    43         private static Vote vote1, vote1a, vote2, vote3, vote4;
     42        private static Vote vote1, vote1a, vote2, vote3, vote4, vote5;
    4443
    4544        static {
     
    4746                issuevalues.put(ISSUE2, VALUE2);
    4847                bid = new Bid(issuevalues);
    49                 vote1 = new Vote(id, bid, 1);
    50                 vote1a = new Vote(id, bid, 1);
     48                vote1 = new Vote(id, bid, 1, 2);
     49                vote1a = new Vote(id, bid, 1, 2);
    5150
    52                 vote2 = new Vote(id2, bid, 1);
     51                vote2 = new Vote(id2, bid, 1, 2);
    5352
    5453                // values swapped, so different issuevalues.
     
    5655                issuevaluesb.put(ISSUE2, VALUE2);
    5756                bidb = new Bid(issuevaluesb);
    58                 vote3 = new Vote(id, bidb, 1);
     57                vote3 = new Vote(id, bidb, 1, 2);
    5958
    60                 vote4 = new Vote(id, bid, 2);
     59                vote4 = new Vote(id, bid, 2, 2);
     60                vote5 = new Vote(id, bid, 1, 3);
    6161
    6262        }
     
    6464        @Override
    6565        public List<List<Vote>> getGeneralTestData() {
    66                 List<List<Vote>> list = new LinkedList<>();
    67                 list.add(Arrays.asList(vote1, vote1a));
    68                 list.add(Arrays.asList(vote2));
    69                 list.add(Arrays.asList(vote3));
    70                 list.add(Arrays.asList(vote4));
    71                 return list;
     66                return Arrays.asList(Arrays.asList(vote1, vote1a), Arrays.asList(vote2),
     67                                Arrays.asList(vote3), Arrays.asList(vote4),
     68                                Arrays.asList(vote5));
    7269        }
    7370
    7471        @Override
    7572        public List<String> getGeneralTestStrings() {
    76                 return Arrays.asList("Vote.*party1.*issue2=10.*issue1=.value1.*1.*",
    77                                 "Vote.*party2.*issue2=10.*issue1=.value1.*1.*",
    78                                 "Vote.*party1.*issue2=10.*issue1=10.*1.*",
    79                                 "Vote.*party1.*issue2=10.*issue1=.value1.*2.*");
     73                return Arrays.asList("Vote.*party1.*issue2=10.*issue1=.value1.*1.*2.*",
     74                                "Vote.*party2.*issue2=10.*issue1=.value1.*1.*2.*",
     75                                "Vote.*party1.*issue2=10.*issue1=10.*1.*2.*",
     76                                "Vote.*party1.*issue2=10.*issue1=.value1.*2.*2.*",
     77                                "Vote.*party1.*issue2=10.*issue1=.value1.*1.*3.*");
    8078        }
    8179
  • events/src/test/java/actions/VotesTest.java

    r21 r22  
    2424public class VotesTest extends GeneralTests<Votes> {
    2525        private final ObjectMapper jackson = new ObjectMapper();
    26         private final String votestring = "{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2}},{\"vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2}}]}}";
     26        private final String votestring = "{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2,\"maxPower\":9}},{\"vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2,\"maxPower\":9}}]}}";
    2727
    2828        private PartyId partyA = new PartyId("partyA");
     
    3030        private Bid bid1 = new Bid("is1", new DiscreteValue("val1")),
    3131                        bid2 = new Bid("is1", new DiscreteValue("val2"));
    32         private Vote voteA1 = new Vote(partyA, bid1, 2);
    33         private Vote voteA2 = new Vote(partyA, bid2, 2);
    34         private Vote voteB1 = new Vote(partyB, bid1, 2);
    35         private Vote voteB2 = new Vote(partyB, bid2, 2);
     32        private Vote voteA1 = new Vote(partyA, bid1, 2, 9);
     33        private Vote voteA2 = new Vote(partyA, bid2, 2, 9);
     34        private Vote voteB1 = new Vote(partyB, bid1, 2, 9);
     35        private Vote voteB2 = new Vote(partyB, bid2, 2, 9);
    3636
    3737        private Votes votes1 = new Votes(partyA, Arrays.asList(voteA1, voteA2));
     
    9595        @Test
    9696        public void isExtendingTestLessPower() {
    97                 Vote powervoteA1 = new Vote(partyA, bid1, 3);
     97                Vote powervoteA1 = new Vote(partyA, bid1, 3, 9);
    9898                Votes powerVotes = new Votes(partyA, Arrays.asList(powervoteA1));
    9999                assertFalse(powerVotes.isExtending(votes1));
     
    103103        @Test(expected = IllegalArgumentException.class)
    104104        public void testDuplicateBidsNotAllowed() {
    105                 Vote voteA1similar = new Vote(partyA, bid1, 3);
     105                Vote voteA1similar = new Vote(partyA, bid1, 3, 9);
    106106                Votes votes = new Votes(partyA, Arrays.asList(voteA1, voteA1similar));
    107107        }
Note: See TracChangeset for help on using the changeset viewer.