Changeset 22 for events/src
- Timestamp:
- 09/22/20 16:26:36 (4 years ago)
- Location:
- events/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
events/src/main/java/geniusweb/actions/Vote.java
r21 r22 14 14 public class Vote extends ActionWithBid { 15 15 private final Integer minPower; 16 private final Integer maxPower; 16 17 17 18 /** … … 19 20 * @param bid the bid that is voted on 20 21 * @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} 23 28 */ 24 29 @JsonCreator 25 30 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) { 27 33 super(id, bid); 28 34 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) { 30 38 throw new IllegalArgumentException( 31 "Vote must have non-null bid and minVotes, and min Votes must be >=1");39 "Vote must have non-null bid and minVotes, and minPower must be >=1 and maxPower must be >=minPower"); 32 40 } 33 41 } … … 35 43 /** 36 44 * 37 * @return the minimum number of votes this bid must get in order for the38 * v ote to be valid.45 * @return the minimum power this bid must get in order for the vote to be 46 * valid. 39 47 */ 40 48 public Integer getMinPower() { … … 42 50 } 43 51 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 44 62 @Override 45 63 public String toString() { 46 return "Vote[" + getActor() + "," + getBid() + "," + minPower + "]"; 64 return "Vote[" + getActor() + "," + getBid() + "," + minPower + "," 65 + maxPower + "]"; 47 66 } 48 67 … … 51 70 final int prime = 31; 52 71 int result = super.hashCode(); 72 result = prime * result 73 + ((maxPower == null) ? 0 : maxPower.hashCode()); 53 74 result = prime * result 54 75 + ((minPower == null) ? 0 : minPower.hashCode()); … … 65 86 return false; 66 87 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; 67 93 if (minPower == null) { 68 94 if (other.minPower != null) -
events/src/test/java/actions/PartyIdTest.java
r1 r22 26 26 } 27 27 28 @SuppressWarnings("unused") 28 29 @Test(expected = IllegalArgumentException.class) 29 30 public void testRestrictions() { … … 31 32 } 32 33 34 @SuppressWarnings("unused") 33 35 @Test(expected = IllegalArgumentException.class) 34 36 public void testRestrictions2() { … … 36 38 } 37 39 40 @SuppressWarnings("unused") 38 41 @Test(expected = IllegalArgumentException.class) 39 42 public void testRestrictions3() { … … 41 44 } 42 45 46 @SuppressWarnings("unused") 43 47 @Test(expected = IllegalArgumentException.class) 44 48 public void testRestrictions4() { … … 46 50 } 47 51 52 @SuppressWarnings("unused") 48 53 @Test(expected = IllegalArgumentException.class) 49 54 public void testRestrictions5() { … … 56 61 } 57 62 63 @SuppressWarnings("unused") 58 64 @Test 59 65 public void testRestrictions6() { … … 61 67 } 62 68 69 @SuppressWarnings("unused") 63 70 @Test 64 71 public void testRestrictions7() { -
events/src/test/java/actions/PartyIdTest1.java
r1 r22 43 43 } 44 44 45 @SuppressWarnings("unused") 45 46 @Test(expected = IllegalArgumentException.class) 46 47 public void smokeTest() throws URISyntaxException { … … 48 49 } 49 50 51 @SuppressWarnings("unused") 50 52 @Test(expected = IllegalArgumentException.class) 51 53 public void nullTest() throws URISyntaxException { -
events/src/test/java/actions/VoteTest.java
r21 r22 6 6 import java.util.Arrays; 7 7 import java.util.HashMap; 8 import java.util.LinkedList;9 8 import java.util.List; 10 9 import java.util.Map; … … 39 38 private final static Value VALUE2 = new NumberValue("10"); 40 39 // 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}}"; 42 41 43 private static Vote vote1, vote1a, vote2, vote3, vote4 ;42 private static Vote vote1, vote1a, vote2, vote3, vote4, vote5; 44 43 45 44 static { … … 47 46 issuevalues.put(ISSUE2, VALUE2); 48 47 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); 51 50 52 vote2 = new Vote(id2, bid, 1 );51 vote2 = new Vote(id2, bid, 1, 2); 53 52 54 53 // values swapped, so different issuevalues. … … 56 55 issuevaluesb.put(ISSUE2, VALUE2); 57 56 bidb = new Bid(issuevaluesb); 58 vote3 = new Vote(id, bidb, 1 );57 vote3 = new Vote(id, bidb, 1, 2); 59 58 60 vote4 = new Vote(id, bid, 2); 59 vote4 = new Vote(id, bid, 2, 2); 60 vote5 = new Vote(id, bid, 1, 3); 61 61 62 62 } … … 64 64 @Override 65 65 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)); 72 69 } 73 70 74 71 @Override 75 72 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.*"); 80 78 } 81 79 -
events/src/test/java/actions/VotesTest.java
r21 r22 24 24 public class VotesTest extends GeneralTests<Votes> { 25 25 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}}]}}"; 27 27 28 28 private PartyId partyA = new PartyId("partyA"); … … 30 30 private Bid bid1 = new Bid("is1", new DiscreteValue("val1")), 31 31 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); 36 36 37 37 private Votes votes1 = new Votes(partyA, Arrays.asList(voteA1, voteA2)); … … 95 95 @Test 96 96 public void isExtendingTestLessPower() { 97 Vote powervoteA1 = new Vote(partyA, bid1, 3 );97 Vote powervoteA1 = new Vote(partyA, bid1, 3, 9); 98 98 Votes powerVotes = new Votes(partyA, Arrays.asList(powervoteA1)); 99 99 assertFalse(powerVotes.isExtending(votes1)); … … 103 103 @Test(expected = IllegalArgumentException.class) 104 104 public void testDuplicateBidsNotAllowed() { 105 Vote voteA1similar = new Vote(partyA, bid1, 3 );105 Vote voteA1similar = new Vote(partyA, bid1, 3, 9); 106 106 Votes votes = new Votes(partyA, Arrays.asList(voteA1, voteA1similar)); 107 107 }
Note:
See TracChangeset
for help on using the changeset viewer.