Changeset 7
- Timestamp:
- 09/25/19 16:49:06 (5 years ago)
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
party/src/test/java/geniusweb/party/inform/NegotiationInfoTest.java
r1 r7 8 8 import java.util.Arrays; 9 9 import java.util.Date; 10 import java.util.HashMap; 10 11 import java.util.List; 12 import java.util.Map; 11 13 12 14 import org.junit.Before; … … 43 45 private Settings negoinfo4; 44 46 private final Date date = new Date(999); 47 private final static ObjectMapper jackson = new ObjectMapper(); 45 48 46 49 @Before … … 48 51 JsonMappingException, IOException { 49 52 // we can't mock because we want to test the serializer 50 ObjectMapper jackson = new ObjectMapper();51 53 ProfileRef profile1 = new ProfileRef(new URI("ws:profile1")); 52 54 // jackson.readValue(serialized, Profile.class); … … 98 100 @Test 99 101 public void testSerialize() throws JsonProcessingException { 100 ObjectMapper jackson = new ObjectMapper();101 102 102 103 String json = jackson.writeValueAsString(negoinfo1); … … 108 109 public void testDeserialize() 109 110 throws JsonParseException, JsonMappingException, IOException { 110 ObjectMapper jackson = new ObjectMapper();111 111 Settings p = (Settings) jackson.readValue(asJson, Inform.class); 112 112 System.out.println(p); 113 113 assertEquals(negoinfo1, p); 114 114 } 115 116 @Test 117 public void testGeneralDict() throws JsonParseException, JsonMappingException, IOException { 118 Map val = jackson.readValue("{\"a\":1,\"b\":{\"x\":3},\"c\":[1,2,3]}", HashMap.class); 119 System.out.println(val); 120 } 115 121 116 122 } -
profile/src/main/java/geniusweb/profile/utilityspace/LinearAdditiveUtilitySpace.java
r4 r7 67 67 @JsonProperty("issueWeights") Map<String, BigDecimal> weights, 68 68 @JsonProperty("reservationBid") Bid resBid) { 69 this.domain = domain; 70 this.name = name; 71 this.reservationBid = resBid; 72 this.issueUtilities.putAll(utils); 73 this.issueWeights.putAll(weights); 74 69 75 if (domain == null) { 70 76 throw new NullPointerException("domain=null"); … … 116 122 + weights.values() + ") must be 1"); 117 123 } 118 this.domain = domain;119 this.name = name;120 this.reservationBid = resBid;121 issueUtilities.putAll(utils);122 issueWeights.putAll(weights);123 124 } 124 125 -
profile/src/test/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilitiesTest.java
r3 r7 2 2 3 3 import static org.junit.Assert.assertEquals; 4 4 import static org.junit.Assert.assertFalse; 5 6 import java.io.IOException; 5 7 import java.math.BigDecimal; 6 8 import java.util.Arrays; … … 10 12 11 13 import org.junit.Test; 14 15 import com.fasterxml.jackson.core.JsonParseException; 16 import com.fasterxml.jackson.databind.JsonMappingException; 17 import com.fasterxml.jackson.databind.ObjectMapper; 12 18 13 19 import geniusweb.issuevalue.DiscreteValue; … … 35 41 private final static DiscreteValueSetUtilities utils, utils1, utilsb, 36 42 utils1b, utilsc1, utilsc2; 43 private static final ObjectMapper jackson = new ObjectMapper(); 37 44 38 45 static { … … 179 186 180 187 } 188 189 @Test 190 public void testIsFittingWrongIssues() 191 throws JsonParseException, JsonMappingException, IOException { 192 // Notice, party tent has extra single quote in the valuesstr. 193 String valuesstr = "{\"values\": [\"Party Tent'\",\"Your Dorm\", \"Party Room\", \"Ballroom\" ]}"; 194 String utilstring = "{\"discreteutils\": {\"valueUtilities\": {\"Party Tent\": 0.52,\"Your Dorm\": 0.23,\"Party Room\": 0.99,\"Ballroom\": 0.77}}}"; 195 ValueSetUtilities valueutils = jackson.readValue(utilstring, 196 ValueSetUtilities.class); 197 ValueSet values = jackson.readValue(valuesstr, ValueSet.class); 198 System.out.println(valueutils.isFitting(values)); 199 assertFalse(valueutils.isFitting(values).isEmpty()); 200 201 } 181 202 } -
profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveSerializationTest.java
r1 r7 20 20 import geniusweb.issuevalue.DiscreteValueSet; 21 21 import geniusweb.issuevalue.Domain; 22 import geniusweb.issuevalue.NumberValue; 23 import geniusweb.issuevalue.NumberValueSet; 22 24 import geniusweb.issuevalue.Value; 23 25 import geniusweb.issuevalue.ValueSet; 24 26 import geniusweb.profile.Profile; 25 import geniusweb.profile.utilityspace.DiscreteValueSetUtilities;26 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;27 import geniusweb.profile.utilityspace.NumberValueSetUtilities;28 import geniusweb.profile.utilityspace.ValueSetUtilities;29 27 30 28 public class LinearAdditiveSerializationTest { … … 39 37 private DiscreteValue i1v1 = new DiscreteValue("issue1value1"); 40 38 private DiscreteValue i1v2 = new DiscreteValue("issue1value2"); 41 private DiscreteValue i2v1 = new DiscreteValue("issue2value1");42 private DiscreteValue i2v2 = new DiscreteValue("issue2value2");39 private NumberValue i2v1 = new NumberValue("0.36"); 40 private NumberValue i2v2 = new NumberValue("0.71"); 43 41 private Domain domain; 44 42 … … 47 45 private BigDecimal TWELVE = new BigDecimal("12"); 48 46 private BigDecimal EIGHTEEN = new BigDecimal("18"); 47 private static final ObjectMapper jackson = new ObjectMapper(); 49 48 50 49 private LinearAdditiveUtilitySpace space; 51 private String serialized = "{\"LinearAdditiveUtilitySpace\":{" 52 + "\"domain\":{\"name\":\"test\"," 53 + "\"issuesValues\":{\"issue2\":{\"values\":[\"issue2value1\",\"issue2value2\"]}," 54 + "\"issue1\":{\"values\":[\"issue1value1\",\"issue1value2\"]}}}," 55 + "\"name\":\"testprofile\"," + "\"issueUtilities\":" 56 + "{\"issue2\":{\"numberutils\":{\"lowValue\":12,\"lowUtility\":0.3,\"highValue\":18,\"highUtility\":0.6}}," 57 + "\"issue1\":{\"discreteutils\":{\"valueUtilities\":{\"issue1value1\":0.2,\"issue1value2\":0.3}}}}," 58 + "\"issueWeights\":{\"issue2\":0.4,\"issue1\":0.6}," 59 + "\"reservationBid\":{\"issuevalues\":{\"issue2\":\"issue2value1\",\"issue1\":\"issue1value2\"}}" 60 + "}" + "}"; 50 51 private String serialized = "{\"LinearAdditiveUtilitySpace\":{\"domain\":{\"name\":\"test\",\"issuesValues\":{\"issue2\":{\"range\":[12,18,1]},\"issue1\":{\"values\":[\"issue1value1\",\"issue1value2\"]}}},\"name\":\"testprofile\",\"issueUtilities\":{\"issue2\":{\"numberutils\":{\"lowValue\":12,\"lowUtility\":0.3,\"highValue\":18,\"highUtility\":0.6}},\"issue1\":{\"discreteutils\":{\"valueUtilities\":{\"issue1value1\":0.2,\"issue1value2\":0.3}}}},\"issueWeights\":{\"issue2\":0.4,\"issue1\":0.6},\"reservationBid\":{\"issuevalues\":{\"issue2\":0.36,\"issue1\":\"issue1value2\"}}}}"; 61 52 62 53 private String jobsjson = "{\"LinearAdditiveUtilitySpace\":{\"issueUtilities\":{" … … 96 87 Map<String, ValueSet> values = new HashMap<>(); 97 88 values.put(ISS1, new DiscreteValueSet(Arrays.asList(i1v1, i1v2))); 98 values.put(ISS2, new DiscreteValueSet(Arrays.asList(i2v1, i2v2)));89 values.put(ISS2, new NumberValueSet(TWELVE, EIGHTEEN, BigDecimal.ONE)); 99 90 domain = new Domain("test", values); 100 91 … … 135 126 @Test 136 127 public void testDeserializeFromValue() throws IOException { 137 ObjectMapper jackson = new ObjectMapper();138 128 assertEquals(space, jackson.readValue(serialized, Profile.class)); 139 129 } … … 141 131 @Test 142 132 public void testDeserializeJobs() throws IOException { 143 ObjectMapper jackson = new ObjectMapper();144 133 Profile jobs = jackson.readValue(jobsjson, Profile.class); 145 134 } -
profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveTest.java
r1 r7 6 6 import static org.mockito.Mockito.when; 7 7 8 import java.io.IOException; 8 9 import java.math.BigDecimal; 10 import java.nio.charset.StandardCharsets; 11 import java.nio.file.Files; 12 import java.nio.file.Paths; 9 13 import java.util.Arrays; 10 14 import java.util.HashMap; … … 14 18 15 19 import org.junit.Test; 20 21 import com.fasterxml.jackson.databind.ObjectMapper; 22 import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; 16 23 17 24 import geniusweb.issuevalue.Bid; … … 21 28 import geniusweb.issuevalue.Value; 22 29 import geniusweb.issuevalue.ValueSet; 23 import geniusweb.profile.utilityspace.DiscreteValueSetUtilities;24 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;25 import geniusweb.profile.utilityspace.ValueSetUtilities;26 30 import tudelft.utilities.junit.GeneralTests; 27 31 … … 54 58 55 59 private static final ValueSetUtilities value1Utils; 60 private static final ObjectMapper jackson = new ObjectMapper(); 56 61 57 62 static { … … 265 270 WEIGHT1.multiply(I1V1UTIL).compareTo(space.getUtility(bid))); 266 271 } 272 273 @Test(expected = InvalidDefinitionException.class) 274 public void loadFullWithJson() throws IOException { 275 String profile = new String( 276 Files.readAllBytes(Paths.get("src/test/resources/party1.json")), 277 StandardCharsets.UTF_8); 278 UtilitySpace space = jackson.readValue(profile, UtilitySpace.class); 279 280 } 267 281 }
Note:
See TracChangeset
for help on using the changeset viewer.