Changeset 3 for profile/src/test/java
- Timestamp:
- 08/29/19 17:09:32 (5 years ago)
- Location:
- profile/src/test/java/geniusweb/profile/utilityspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
profile/src/test/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilitiesTest.java
r1 r3 1 1 package geniusweb.profile.utilityspace; 2 3 import static org.junit.Assert.assertEquals; 2 4 3 5 import java.math.BigDecimal; … … 10 12 11 13 import geniusweb.issuevalue.DiscreteValue; 12 import geniusweb.profile.utilityspace.DiscreteValueSetUtilities; 14 import geniusweb.issuevalue.DiscreteValueSet; 15 import geniusweb.issuevalue.NumberValue; 16 import geniusweb.issuevalue.NumberValueSet; 17 import geniusweb.issuevalue.ValueSet; 13 18 import tudelft.utilities.junit.GeneralTests; 14 19 15 public class DiscreteValueSetUtilitiesTest extends GeneralTests<DiscreteValueSetUtilities> { 20 public class DiscreteValueSetUtilitiesTest 21 extends GeneralTests<DiscreteValueSetUtilities> { 16 22 17 23 private final static DiscreteValue vala = new DiscreteValue("a"); 18 24 private final static DiscreteValue vala1 = new DiscreteValue("a"); 19 25 private final static DiscreteValue valb = new DiscreteValue("b"); 26 private final static NumberValue valn = new NumberValue("99"); 20 27 21 28 private final static BigDecimal util = new BigDecimal("0.14"); … … 23 30 private final static BigDecimal utilb = new BigDecimal("0.37"); 24 31 25 private final static DiscreteValueSetUtilities utils, utils1, utilsb, utils1b, utilsc1, utilsc2; 32 private final static BigDecimal badutil = new BigDecimal("1.37"); 33 private final static BigDecimal badutil2 = new BigDecimal("-0.37"); 34 35 private final static DiscreteValueSetUtilities utils, utils1, utilsb, 36 utils1b, utilsc1, utilsc2; 26 37 27 38 static { … … 56 67 @Override 57 68 public List<List<DiscreteValueSetUtilities>> getGeneralTestData() { 58 return Arrays.asList(Arrays.asList(utils, utils1), Arrays.asList(utilsb), Arrays.asList(utils1b), 69 return Arrays.asList(Arrays.asList(utils, utils1), 70 Arrays.asList(utilsb), Arrays.asList(utils1b), 59 71 Arrays.asList(utilsc1, utilsc2)); 60 72 } … … 62 74 @Override 63 75 public List<String> getGeneralTestStrings() { 64 return Arrays.asList("ValueSetUtilities\\{\"a\"=0.14\\}", "ValueSetUtilities\\{\"b\"=0.37\\}", 65 "ValueSetUtilities\\{\"a\"=0.37\\}", "ValueSetUtilities\\{\"a\"=0.14, \"b\"=0.37\\}"); 76 return Arrays.asList("ValueSetUtilities\\{\"a\"=0.14\\}", 77 "ValueSetUtilities\\{\"b\"=0.37\\}", 78 "ValueSetUtilities\\{\"a\"=0.37\\}", 79 "ValueSetUtilities\\{\"a\"=0.14, \"b\"=0.37\\}"); 66 80 } 67 81 … … 72 86 } 73 87 88 @Test(expected = IllegalArgumentException.class) 89 public void testTooLargeUtility() { 90 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 91 valueUtils.put(vala, util); 92 valueUtils.put(valb, badutil); 93 new DiscreteValueSetUtilities(valueUtils); 94 } 95 96 @Test(expected = IllegalArgumentException.class) 97 public void testNegativeUtility() { 98 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 99 valueUtils.put(vala, util); 100 valueUtils.put(valb, badutil2); 101 new DiscreteValueSetUtilities(valueUtils); 102 } 103 104 @Test(expected = IllegalArgumentException.class) 105 public void testNullUtility() { 106 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 107 valueUtils.put(vala, null); 108 valueUtils.put(valb, util); 109 new DiscreteValueSetUtilities(valueUtils); 110 } 111 112 @Test(expected = NullPointerException.class) 113 public void testNullValueUtils() { 114 new DiscreteValueSetUtilities(null); 115 116 } 117 118 @Test(expected = NullPointerException.class) 119 public void testNullIssue() { 120 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 121 valueUtils.put(vala, util); 122 valueUtils.put(null, utilb); 123 new DiscreteValueSetUtilities(valueUtils); 124 } 125 126 @Test 127 public void testGetUtility() { 128 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 129 valueUtils.put(vala, util); 130 valueUtils.put(valb, utilb); 131 DiscreteValueSetUtilities utilset = new DiscreteValueSetUtilities( 132 valueUtils); 133 assertEquals(util, utilset.getUtility(vala)); 134 assertEquals(utilb, utilset.getUtility(valb)); 135 assertEquals(BigDecimal.ZERO, 136 utilset.getUtility(new DiscreteValue("unknownIssue"))); 137 138 } 139 140 @Test 141 public void testIsFitting() { 142 ValueSet valueset = new DiscreteValueSet(Arrays.asList(vala, valb)); 143 144 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 145 valueUtils.put(vala, util); 146 DiscreteValueSetUtilities utilset = new DiscreteValueSetUtilities( 147 valueUtils); 148 149 assertEquals( 150 "The values in the set DiscreteValueSet[\"a\", \"b\"] do not match the values mapped to utilities [\"a\"]", 151 utilset.isFitting(valueset)); 152 153 valueUtils.put(valb, utilb); 154 utilset = new DiscreteValueSetUtilities(valueUtils); 155 assertEquals(null, utilset.isFitting(valueset)); 156 157 valueUtils.put(new DiscreteValue("unknownIssue"), util1); 158 utilset = new DiscreteValueSetUtilities(valueUtils); 159 assertEquals( 160 "The values in the set DiscreteValueSet[\"a\", \"b\"] do not match the values mapped to utilities [\"a\", \"b\", \"unknownIssue\"]", 161 utilset.isFitting(valueset)); 162 163 } 164 165 @Test 166 public void testIsFittingWrongType() { 167 ValueSet valueset = new NumberValueSet(BigDecimal.ZERO, BigDecimal.ONE, 168 new BigDecimal("0.3")); 169 170 Map<DiscreteValue, BigDecimal> valueUtils = new HashMap<>(); 171 valueUtils.put(vala, util); 172 valueUtils.put(valb, utilb); 173 DiscreteValueSetUtilities utilset = new DiscreteValueSetUtilities( 174 valueUtils); 175 176 assertEquals( 177 "The utilities are for a discrete valueset but the given values are numberValueSet[0,1,0.3]", 178 utilset.isFitting(valueset)); 179 180 } 74 181 } -
profile/src/test/java/geniusweb/profile/utilityspace/NumberValueSetUtilTest.java
r1 r3 9 9 import org.junit.Test; 10 10 11 import geniusweb.issuevalue.DiscreteValue; 12 import geniusweb.issuevalue.DiscreteValueSet; 11 13 import geniusweb.issuevalue.NumberValue; 12 import geniusweb.profile.utilityspace.NumberValueSetUtilities; 14 import geniusweb.issuevalue.NumberValueSet; 15 import geniusweb.issuevalue.ValueSet; 16 import tudelft.utilities.immutablelist.Range; 13 17 import tudelft.utilities.junit.GeneralTests; 14 18 15 public class NumberValueSetUtilTest extends GeneralTests<NumberValueSetUtilities> { 19 public class NumberValueSetUtilTest 20 extends GeneralTests<NumberValueSetUtilities> { 16 21 17 22 private static final BigDecimal lowval1 = new BigDecimal("12.5"); … … 21 26 private static final BigDecimal highvalb = new BigDecimal("18.4"); 22 27 private static final BigDecimal highutil = new BigDecimal("0.9"); 23 private static final NumberValueSetUtilities valueset1 = new NumberValueSetUtilities(lowval1, low1util, highval, 24 highutil); 25 private static final NumberValueSetUtilities valueset1b = new NumberValueSetUtilities(lowval1, low1util, highval, 26 highutil); 27 private static final NumberValueSetUtilities valueset2 = new NumberValueSetUtilities(lowval1, low1utilb, highval, 28 highutil); 29 private static final NumberValueSetUtilities valueset3 = new NumberValueSetUtilities(lowval1, low1util, highvalb, 30 highutil); 28 private static final NumberValueSetUtilities valueset1 = new NumberValueSetUtilities( 29 lowval1, low1util, highval, highutil); 30 private static final NumberValueSetUtilities valueset1b = new NumberValueSetUtilities( 31 lowval1, low1util, highval, highutil); 32 private static final NumberValueSetUtilities valueset2 = new NumberValueSetUtilities( 33 lowval1, low1utilb, highval, highutil); 34 private static final NumberValueSetUtilities valueset3 = new NumberValueSetUtilities( 35 lowval1, low1util, highvalb, highutil); 36 private static final BigDecimal ZERO_1 = new BigDecimal("0.1"); 31 37 32 38 @Override 33 39 public List<List<NumberValueSetUtilities>> getGeneralTestData() { 34 return Arrays.asList(Arrays.asList(valueset1, valueset1b), Arrays.asList(valueset2), Arrays.asList(valueset3)); 40 return Arrays.asList(Arrays.asList(valueset1, valueset1b), 41 Arrays.asList(valueset2), Arrays.asList(valueset3)); 35 42 } 36 43 37 44 @Override 38 45 public List<String> getGeneralTestStrings() { 39 return Arrays.asList("NumberValUtility\\(12.5->0.5,18.5->0.9\\)", "NumberValUtility\\(12.5->0.6,18.5->0.9\\)", 46 return Arrays.asList("NumberValUtility\\(12.5->0.5,18.5->0.9\\)", 47 "NumberValUtility\\(12.5->0.6,18.5->0.9\\)", 40 48 "NumberValUtility\\(12.5->0.5,18.4->0.9\\)"); 41 49 } … … 49 57 public void utilAscentingTest() { 50 58 NumberValueSetUtilities utils = valueset1; 51 assertEquals(0, low1util.compareTo(utils.getUtility(new NumberValue(lowval1)))); 59 assertEquals(0, 60 low1util.compareTo(utils.getUtility(new NumberValue(lowval1)))); 52 61 } 53 62 54 63 @Test 55 64 public void utilDescendingTest() { 56 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, highutil, highval, low1util); 57 assertEquals(0, highutil.compareTo(utils.getUtility(new NumberValue(lowval1)))); 65 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 66 highutil, highval, low1util); 67 assertEquals(0, 68 highutil.compareTo(utils.getUtility(new NumberValue(lowval1)))); 58 69 } 59 70 60 71 @Test(expected = IllegalArgumentException.class) 61 72 public void reverserangetest() { 62 NumberValueSetUtilities utils = new NumberValueSetUtilities(highval, highutil, lowval1, low1util); 73 NumberValueSetUtilities utils = new NumberValueSetUtilities(highval, 74 low1util, highval, highutil); 75 } 76 77 @Test(expected = NullPointerException.class) 78 public void testNullHigh() { 79 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 80 low1util, null, highutil); 81 } 82 83 @Test(expected = NullPointerException.class) 84 public void testNullHighUtil() { 85 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 86 low1util, highval, null); 87 } 88 89 @Test(expected = NullPointerException.class) 90 public void testNullLow() { 91 NumberValueSetUtilities utils = new NumberValueSetUtilities(null, 92 low1util, highval, highutil); 93 } 94 95 @Test(expected = NullPointerException.class) 96 public void testNullLowUtil() { 97 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 98 null, highval, highutil); 99 } 100 101 @Test(expected = IllegalArgumentException.class) 102 public void testLowUtilNegative() { 103 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 104 new BigDecimal("-0.2"), highval, highutil); 105 } 106 107 @Test(expected = IllegalArgumentException.class) 108 public void testHighUtilNegative() { 109 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 110 low1util, highval, new BigDecimal("-0.000003")); 111 } 112 113 @Test 114 public void getUtilTest() { 115 NumberValueSetUtilities utils = new NumberValueSetUtilities(lowval1, 116 low1util, highval, highutil); 117 assertEquals(0, 118 highutil.compareTo(utils.getUtility(new NumberValue(highval)))); 119 assertEquals(0, 120 low1util.compareTo(utils.getUtility(new NumberValue(lowval1)))); 121 // linear interpolated , check center 122 BigDecimal middleutil = low1util.add(highutil) 123 .divide(new BigDecimal("2")); 124 NumberValue middleval = new NumberValue( 125 lowval1.add(highval).divide(new BigDecimal("2"))); 126 assertEquals(0, middleutil.compareTo(utils.getUtility(middleval))); 127 128 } 129 130 @Test 131 public void testIsNotFittingRange() { 132 ValueSet valueset = new NumberValueSet( 133 new Range(low1util, highutil, new BigDecimal("0.02"))); 134 ValueSetUtilities utilset = new NumberValueSetUtilities(lowval1, 135 low1util, highval, highutil); 136 assertEquals( 137 "the utilities are specified down to 12.5 but the valueset starts at 0.5", 138 utilset.isFitting(valueset)); 139 } 140 141 @Test 142 public void testTopOfRangeTooLarge() { 143 ValueSet valueset = new NumberValueSet( 144 new Range(lowval1, highval.subtract(ZERO_1), ZERO_1)); 145 ValueSetUtilities utilset = new NumberValueSetUtilities(lowval1, 146 low1util, highval, highutil); 147 assertEquals( 148 "the utilities are specified up to 18.5 but the valueset ends at 18.4", 149 utilset.isFitting(valueset)); 150 } 151 152 @Test 153 public void testIsFitting() { 154 ValueSet valueset = new NumberValueSet( 155 new Range(lowval1, highval, BigDecimal.ONE)); 156 ValueSetUtilities utilset = new NumberValueSetUtilities(lowval1, 157 low1util, highval, highutil); 158 assertEquals(null, utilset.isFitting(valueset)); 159 } 160 161 @Test 162 public void testIsFittingWrongType() { 163 DiscreteValue vala = new DiscreteValue("a"); 164 DiscreteValue valb = new DiscreteValue("b"); 165 ValueSet valueset = new DiscreteValueSet(Arrays.asList(vala, valb)); 166 167 NumberValueSetUtilities utilset = new NumberValueSetUtilities(lowval1, 168 low1util, highval, highutil); 169 assertEquals( 170 "The utilities are for a number valueset but the given values are DiscreteValueSet[\"a\", \"b\"]", 171 utilset.isFitting(valueset)); 172 63 173 } 64 174
Note:
See TracChangeset
for help on using the changeset viewer.