Changeset 7 for profile/src/test


Ignore:
Timestamp:
09/25/19 16:49:06 (5 years ago)
Author:
bart
Message:

Fix consistency check LinearAdditiveUtilitySpace

Location:
profile/src/test
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • profile/src/test/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilitiesTest.java

    r3 r7  
    22
    33import static org.junit.Assert.assertEquals;
    4 
     4import static org.junit.Assert.assertFalse;
     5
     6import java.io.IOException;
    57import java.math.BigDecimal;
    68import java.util.Arrays;
     
    1012
    1113import org.junit.Test;
     14
     15import com.fasterxml.jackson.core.JsonParseException;
     16import com.fasterxml.jackson.databind.JsonMappingException;
     17import com.fasterxml.jackson.databind.ObjectMapper;
    1218
    1319import geniusweb.issuevalue.DiscreteValue;
     
    3541        private final static DiscreteValueSetUtilities utils, utils1, utilsb,
    3642                        utils1b, utilsc1, utilsc2;
     43        private static final ObjectMapper jackson = new ObjectMapper();
    3744
    3845        static {
     
    179186
    180187        }
     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        }
    181202}
  • profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveSerializationTest.java

    r1 r7  
    2020import geniusweb.issuevalue.DiscreteValueSet;
    2121import geniusweb.issuevalue.Domain;
     22import geniusweb.issuevalue.NumberValue;
     23import geniusweb.issuevalue.NumberValueSet;
    2224import geniusweb.issuevalue.Value;
    2325import geniusweb.issuevalue.ValueSet;
    2426import 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;
    2927
    3028public class LinearAdditiveSerializationTest {
     
    3937        private DiscreteValue i1v1 = new DiscreteValue("issue1value1");
    4038        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");
    4341        private Domain domain;
    4442
     
    4745        private BigDecimal TWELVE = new BigDecimal("12");
    4846        private BigDecimal EIGHTEEN = new BigDecimal("18");
     47        private static final ObjectMapper jackson = new ObjectMapper();
    4948
    5049        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\"}}}}";
    6152
    6253        private String jobsjson = "{\"LinearAdditiveUtilitySpace\":{\"issueUtilities\":{"
     
    9687                Map<String, ValueSet> values = new HashMap<>();
    9788                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));
    9990                domain = new Domain("test", values);
    10091
     
    135126        @Test
    136127        public void testDeserializeFromValue() throws IOException {
    137                 ObjectMapper jackson = new ObjectMapper();
    138128                assertEquals(space, jackson.readValue(serialized, Profile.class));
    139129        }
     
    141131        @Test
    142132        public void testDeserializeJobs() throws IOException {
    143                 ObjectMapper jackson = new ObjectMapper();
    144133                Profile jobs = jackson.readValue(jobsjson, Profile.class);
    145134        }
  • profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveTest.java

    r1 r7  
    66import static org.mockito.Mockito.when;
    77
     8import java.io.IOException;
    89import java.math.BigDecimal;
     10import java.nio.charset.StandardCharsets;
     11import java.nio.file.Files;
     12import java.nio.file.Paths;
    913import java.util.Arrays;
    1014import java.util.HashMap;
     
    1418
    1519import org.junit.Test;
     20
     21import com.fasterxml.jackson.databind.ObjectMapper;
     22import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
    1623
    1724import geniusweb.issuevalue.Bid;
     
    2128import geniusweb.issuevalue.Value;
    2229import geniusweb.issuevalue.ValueSet;
    23 import geniusweb.profile.utilityspace.DiscreteValueSetUtilities;
    24 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
    25 import geniusweb.profile.utilityspace.ValueSetUtilities;
    2630import tudelft.utilities.junit.GeneralTests;
    2731
     
    5458
    5559        private static final ValueSetUtilities value1Utils;
     60        private static final ObjectMapper jackson = new ObjectMapper();
    5661
    5762        static {
     
    265270                                WEIGHT1.multiply(I1V1UTIL).compareTo(space.getUtility(bid)));
    266271        }
     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        }
    267281}
Note: See TracChangeset for help on using the changeset viewer.