Changeset 53 for profile/src/test/java/geniusweb
- Timestamp:
- 12/18/24 13:28:59 (5 days ago)
- Location:
- profile/src/test/java/geniusweb/profile
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
profile/src/test/java/geniusweb/profile/DefaultPartialOrderingTest.java
r52 r53 27 27 import tudelft.utilities.junit.GeneralTests; 28 28 29 public class DefaultPartialOrderingTest extends GeneralTests<DefaultPartialOrdering> { 29 public class DefaultPartialOrderingTest 30 extends GeneralTests<DefaultPartialOrdering> { 30 31 31 private final String serialized = "{\"DefaultPartialOrdering\":{" + "\"name\":\"ordering1\"," 32 private final String serialized = "{\"DefaultPartialOrdering\":{" 33 + "\"name\":\"ordering1\"," 32 34 + "\"domain\":{\"name\":\"dom1\",\"issuesValues\":{\"iss1\":{\"values\":[\"1\",\"2\",\"3\"]}}}," 33 + "\"reservationBid\":{\"issuevalues\":{\"iss1\":\"1\"}}," 34 + "\"bids\":[{\"issuevalues\":{\"iss1\":\"1\"}},{\"issuevalues\":{\"iss1\":\"3\"}},{\"issuevalues\":{\"iss1\":\"2\"}}]," 35 + "\"better\":[[0,2],[1,2]]}}"; 35 + "\"better\":{\"{\\\"issuevalues\\\":{\\\"iss1\\\":\\\"1\\\"}}\":[{\"issuevalues\":{\"iss1\":\"2\"}}],\"{\\\"issuevalues\\\":{\\\"iss1\\\":\\\"3\\\"}}\":[{\"issuevalues\":{\"iss1\":\"2\"}}]}," 36 + "\"reservationbid\":{\"issuevalues\":{\"iss1\":\"1\"}}}}"; 36 37 37 38 // we need real (not mock) values otherwise serializer crashes.. 38 39 private String issue1 = "iss1"; 39 private DefaultPartialOrdering ordering1, ordering1b, ordering2, ordering3, ordering4, ordering5; 40 private DefaultPartialOrdering ordering1, ordering1b, ordering2, ordering3, 41 ordering4, ordering5; 40 42 41 43 private Bid bid1, bid2, bid3; … … 47 49 DiscreteValue val2 = new DiscreteValue("2"); 48 50 DiscreteValue val3 = new DiscreteValue("3"); 49 issues.put(issue1, new DiscreteValueSet(new HashSet<>(Arrays.asList(val1, val2, val3)))); 51 issues.put(issue1, new DiscreteValueSet( 52 new HashSet<>(Arrays.asList(val1, val2, val3)))); 50 53 Domain domain1 = new Domain("dom1", issues); 51 54 Domain domain2 = new Domain("dom2", issues); … … 62 65 map2.put(bid3, new HashSet<Bid>(Arrays.asList(bid1))); 63 66 64 ordering1 = new DefaultPartialOrdering("ordering1", domain1, bid1, map1); 65 ordering1b = new DefaultPartialOrdering("ordering1", domain1, bid1, map1); 66 ordering2 = new DefaultPartialOrdering("ordering2", domain1, bid1, map1); 67 ordering3 = new DefaultPartialOrdering("ordering1", domain2, bid1, map1); 68 ordering4 = new DefaultPartialOrdering("ordering1", domain1, bid2, map1); 69 ordering5 = new DefaultPartialOrdering("ordering1", domain1, bid1, map2); 67 ordering1 = new DefaultPartialOrdering("ordering1", domain1, bid1, 68 map1); 69 ordering1b = new DefaultPartialOrdering("ordering1", domain1, bid1, 70 map1); 71 ordering2 = new DefaultPartialOrdering("ordering2", domain1, bid1, 72 map1); 73 ordering3 = new DefaultPartialOrdering("ordering1", domain2, bid1, 74 map1); 75 ordering4 = new DefaultPartialOrdering("ordering1", domain1, bid2, 76 map1); 77 ordering5 = new DefaultPartialOrdering("ordering1", domain1, bid1, 78 map2); 70 79 71 80 } … … 73 82 @Override 74 83 public List<List<DefaultPartialOrdering>> getGeneralTestData() { 75 return Arrays.asList(Arrays.asList(ordering1, ordering1b), Arrays.asList(ordering2), Arrays.asList(ordering3), 84 return Arrays.asList(Arrays.asList(ordering1, ordering1b), 85 Arrays.asList(ordering2), Arrays.asList(ordering3), 76 86 Arrays.asList(ordering4), Arrays.asList(ordering5)); 77 87 } … … 79 89 @Override 80 90 public List<String> getGeneralTestStrings() { 81 return Arrays.asList("DefaultPartialOrdering.*", "DefaultPartialOrdering.*", "DefaultPartialOrdering.*", 91 return Arrays.asList("DefaultPartialOrdering.*", 92 "DefaultPartialOrdering.*", "DefaultPartialOrdering.*", 82 93 "DefaultPartialOrdering.*", "DefaultPartialOrdering.*"); 83 94 } -
profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveTest.java
r52 r53 22 22 23 23 import com.fasterxml.jackson.databind.ObjectMapper; 24 import com.fasterxml.jackson.databind.exc.ValueInstantiationException; 24 25 25 26 import geniusweb.issuevalue.Bid; … … 309 310 } 310 311 312 /** 313 * This should throw because computersell-domainmismatch has a mismatch: it 314 * has "high 32G" as graphics option, but the utilities have no value for 315 * that. Instead it talks about "high 24G" 316 */ 317 @Test(expected = ValueInstantiationException.class) 318 public void testIsFitting() throws IOException { 319 String profile = new String( 320 Files.readAllBytes(Paths.get( 321 "src/test/resources/computersell-domainmismatch.json")), 322 StandardCharsets.UTF_8); 323 UtilitySpace space = jackson.readValue(profile, UtilitySpace.class); 324 325 } 326 311 327 } -
profile/src/test/java/geniusweb/profile/utilityspace/SumOfGroupsUtilitySpaceTest.java
r52 r53 21 21 import org.junit.Test; 22 22 23 import com.fasterxml.jackson.core.JsonParseException; 23 24 import com.fasterxml.jackson.core.JsonProcessingException; 25 import com.fasterxml.jackson.databind.JsonMappingException; 24 26 import com.fasterxml.jackson.databind.ObjectMapper; 27 import com.fasterxml.jackson.databind.exc.ValueInstantiationException; 25 28 26 29 import geniusweb.issuevalue.Bid; … … 34 37 import tudelft.utilities.immutablelist.ImmutableList; 35 38 import tudelft.utilities.immutablelist.Outer; 36 37 public class SumOfGroupsUtilitySpaceTest { 39 import tudelft.utilities.junit.GeneralTests; 40 41 public class SumOfGroupsUtilitySpaceTest 42 extends GeneralTests<SumOfGroupsUtilitySpace> { 38 43 private final ObjectMapper jackson = new ObjectMapper(); 39 44 private SumOfGroupsUtilitySpace pa1; … … 49 54 50 55 private Domain domain; 51 private PartsUtilities putils12, putils3 ;56 private PartsUtilities putils12, putils3, putils3b; 52 57 private String serialized = "{\"SumOfGroupsUtilitySpace\":{\"domain\":{\"name\":\"domain\",\"issuesValues\":{\"issue3\":{\"values\":[\"low\",\"high\"]},\"issue2\":{\"values\":[\"low\",\"high\"]},\"issue1\":{\"values\":[\"low\",\"high\"]}}},\"name\":\"testspace\",\"partUtilities\":{\"1and2\":{\"PartsUtilities\":{\"issues\":[\"issue1\",\"issue2\"],\"utilslist\":[{\"values\":[\"low\",\"low\"],\"util\":0.16},{\"values\":[\"high\",\"high\"],\"util\":0.72},{\"values\":[\"low\",\"high\"],\"util\":0.16},{\"values\":[\"high\",\"low\"],\"util\":0.16}]}},\"3\":{\"PartsUtilities\":{\"issues\":[\"issue3\"],\"utilslist\":[{\"values\":[\"low\"],\"util\":0.16},{\"values\":[\"high\"],\"util\":0.14}]}}},\"reservationbid\":{\"issuevalues\":{\"issue1\":\"high\"}}}}"; 58 private SumOfGroupsUtilitySpace sog1, sog1a, sog2, sog3; 53 59 54 60 @Before … … 78 84 putils3 = new PartsUtilities(Arrays.asList(iss3), utils3); 79 85 86 Map<ProductOfValue, BigDecimal> utils3b = new HashMap<>(); 87 utils3b.put(new ProductOfValue(Arrays.asList(lo)), N07.multiply(N02)); 88 utils3b.put(new ProductOfValue(Arrays.asList(hi)), N08.multiply(N02)); 89 putils3b = new PartsUtilities(Arrays.asList(iss3), utils3b); 90 91 HashMap<String, PartsUtilities> partutils = new HashMap<>(); 92 partutils.put("1and2", putils12); 93 partutils.put("3", putils3); 94 95 sog1 = new SumOfGroupsUtilitySpace(domain, "testspace", partutils, 96 resBid); 97 sog1a = new SumOfGroupsUtilitySpace(domain, "testspace", partutils, 98 resBid); 99 sog2 = new SumOfGroupsUtilitySpace(domain, "testspace2", partutils, 100 resBid); 101 102 // reuse partutils. Also checks that the values have been copied 103 partutils = new HashMap<>(); 104 partutils.put("1and2", putils12); 105 partutils.put("3", putils3b); 106 sog3 = new SumOfGroupsUtilitySpace(domain, "testspace", partutils, 107 resBid); 108 109 } 110 111 @Override 112 public List<List<SumOfGroupsUtilitySpace>> getGeneralTestData() { 113 return Arrays.asList(Arrays.asList(sog1, sog1a), Arrays.asList(sog2), 114 Arrays.asList(sog3)); 115 } 116 117 @Override 118 public List<String> getGeneralTestStrings() { 119 return Arrays.asList( 120 "SumOfGroupsUtilitySpace.*testspace.*1and2.*PartsUtilities.*issue1.*issue2.*3.*PartsUtilities.*Bid.*issue1.*high.*", 121 "SumOfGroupsUtilitySpace.*testspace2.*1and2.*PartsUtilities.*issue1.*issue2.*3.*PartsUtilities.*Bid.*issue1.*high.*", 122 "SumOfGroupsUtilitySpace.*testspace.*1and2.*PartsUtilities.*issue1.*issue2.*3.*PartsUtilities.*Bid.*issue1.*high.*"); 80 123 } 81 124 … … 161 204 LinearAdditiveUtilitySpace las = jackson.readValue(profile, 162 205 LinearAdditiveUtilitySpace.class); 163 SumOfGroupsUtilitySpace pas = new SumOfGroupsUtilitySpace(las);206 SumOfGroupsUtilitySpace pas = SumOfGroupsUtilitySpace.create(las); 164 207 checkUtilitiesAllEqual(las, pas); 165 208 System.out.println("Generated partial profile:\n" + pas); … … 178 221 LinearAdditiveUtilitySpace las = jackson.readValue(profile, 179 222 LinearAdditiveUtilitySpace.class); 180 SumOfGroupsUtilitySpace pas = new SumOfGroupsUtilitySpace(las);223 SumOfGroupsUtilitySpace pas = SumOfGroupsUtilitySpace.create(las); 181 224 pas = pas.group(Arrays.asList("Food", "Drinks"), "food&drinks"); 182 225 checkUtilitiesAllEqual(las, pas); … … 235 278 } 236 279 280 @Test 281 public void loadComputerBuy() throws IOException { 282 UtilitySpace space = jackson.readValue( 283 getClass().getResourceAsStream("/computerbuy.json"), 284 UtilitySpace.class); 285 assertTrue(space instanceof SumOfGroupsUtilitySpace); 286 287 } 288 289 @Test 290 public void loadComputerSell() throws IOException { 291 UtilitySpace space = jackson.readValue( 292 getClass().getResourceAsStream("/computersell.json"), 293 UtilitySpace.class); 294 assertTrue(space instanceof LinearAdditiveUtilitySpace); 295 296 } 297 298 @Test(expected = ValueInstantiationException.class) 299 public void loadComputerBuyIncomplete() throws IOException { 300 UtilitySpace space = jackson.readValue( 301 getClass().getResourceAsStream("/computerbuyincomplete.json"), 302 UtilitySpace.class); 303 assertTrue(space instanceof LinearAdditiveUtilitySpace); 304 305 } 306 307 @Test 308 public void loadComputerBuyNumbers() throws IOException { 309 UtilitySpace space = jackson.readValue( 310 getClass().getResourceAsStream("/computerbuynumbers.json"), 311 UtilitySpace.class); 312 assertTrue(space instanceof SumOfGroupsUtilitySpace); 313 314 } 315 316 @Test 317 public void testComputerBuyUtility() 318 throws JsonParseException, JsonMappingException, IOException { 319 SumOfGroupsUtilitySpace space = jackson.readValue( 320 getClass().getResourceAsStream("/computerbuy.json"), 321 SumOfGroupsUtilitySpace.class); 322 Bid bid = space.getReservationBid(); 323 assertEquals(new BigDecimal("0.625"), space.getUtility(bid)); 324 } 325 237 326 /************************ PRIVATE FUNCTIONS *******************/ 238 327
Note:
See TracChangeset
for help on using the changeset viewer.