[52] | 1 | package geniusweb.opponentmodel.bayesian;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 |
|
---|
| 5 | import java.math.BigDecimal;
|
---|
| 6 | import java.util.Arrays;
|
---|
| 7 | import java.util.List;
|
---|
| 8 |
|
---|
| 9 | import org.junit.Before;
|
---|
| 10 | import org.junit.Test;
|
---|
| 11 |
|
---|
| 12 | import geniusweb.issuevalue.NumberValue;
|
---|
| 13 | import tudelft.utilities.junit.GeneralTests;
|
---|
| 14 |
|
---|
| 15 | public class TriangleValueSetUtilTest
|
---|
| 16 | extends GeneralTests<TriangleValueSetUtilities> {
|
---|
| 17 |
|
---|
| 18 | private static final double MAXE = 0.00000001;
|
---|
| 19 | private static final BigDecimal N0 = BigDecimal.ZERO;
|
---|
| 20 | private static final BigDecimal N01 = new BigDecimal("0.1");
|
---|
| 21 | private static final BigDecimal N02 = new BigDecimal("0.2");
|
---|
| 22 | private static final BigDecimal N03 = new BigDecimal("0.3");
|
---|
| 23 | private static final BigDecimal N04 = new BigDecimal("0.4");
|
---|
| 24 | private static final BigDecimal N05 = new BigDecimal("0.5");
|
---|
| 25 | private static final BigDecimal N07 = new BigDecimal("0.7");
|
---|
| 26 | private static final BigDecimal N09 = new BigDecimal("0.9");
|
---|
| 27 | private static final BigDecimal N1 = BigDecimal.ONE;
|
---|
| 28 |
|
---|
| 29 | private TriangleValueSetUtilities vset1, vset1a, vset2, vset3;
|
---|
| 30 |
|
---|
| 31 | @Before
|
---|
| 32 | public void before() {
|
---|
| 33 | vset1 = new TriangleValueSetUtilities(N01, N02, N04, N05, N07, N09);
|
---|
| 34 | vset1a = new TriangleValueSetUtilities(N01, N02, N04, N05, N07, N09);
|
---|
| 35 | vset2 = new TriangleValueSetUtilities(N01, N02, N01, N05, N07, N09);
|
---|
| 36 | vset3 = new TriangleValueSetUtilities(N01, N02, N07, N05, N07, N09);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @Override
|
---|
| 40 | public List<List<TriangleValueSetUtilities>> getGeneralTestData() {
|
---|
| 41 | return Arrays.asList(Arrays.asList(vset1, vset1a), Arrays.asList(vset2),
|
---|
| 42 | Arrays.asList(vset3));
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | @Override
|
---|
| 46 | public List<String> getGeneralTestStrings() {
|
---|
| 47 | return Arrays.asList(
|
---|
| 48 | "TriangleValueSetUtilities.0.1->0.2,0.4->0.5,0.7->0.9.",
|
---|
| 49 | "TriangleValueSetUtilities.0.1->0.2,0.1->0.5,0.7->0.9.",
|
---|
| 50 | "TriangleValueSetUtilities.0.1->0.2,0.7->0.5,0.7->0.9.");
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | @Test
|
---|
| 54 | public void testInterpolation() {
|
---|
| 55 | assertEquals(0, vset1.getUtility(new NumberValue(N0)).doubleValue(),
|
---|
| 56 | MAXE);
|
---|
| 57 | assertEquals(0.2, vset1.getUtility(new NumberValue(N01)).doubleValue(),
|
---|
| 58 | MAXE);
|
---|
| 59 | assertEquals(0.3 /* 2 + 1/2*3 */,
|
---|
| 60 | vset1.getUtility(new NumberValue(N02)).doubleValue(), MAXE);
|
---|
| 61 | assertEquals(0.5, vset1.getUtility(new NumberValue(N04)).doubleValue(),
|
---|
| 62 | MAXE);
|
---|
| 63 | assertEquals(0.9, vset1.getUtility(new NumberValue(N07)).doubleValue(),
|
---|
| 64 | MAXE);
|
---|
| 65 | assertEquals(0, vset1.getUtility(new NumberValue(N09)).doubleValue(),
|
---|
| 66 | MAXE);
|
---|
| 67 |
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | @Test
|
---|
| 71 | public void testMidEqualsLow() {
|
---|
| 72 | assertEquals(0, vset2.getUtility(new NumberValue(N0)).doubleValue(),
|
---|
| 73 | MAXE);
|
---|
| 74 | assertEquals(0.5, vset2.getUtility(new NumberValue(N01)).doubleValue(),
|
---|
| 75 | MAXE);
|
---|
| 76 | assertEquals(0.5 + 0.4 / 6,
|
---|
| 77 | vset2.getUtility(new NumberValue(N02)).doubleValue(), MAXE);
|
---|
| 78 | assertEquals(0.9, vset2.getUtility(new NumberValue(N07)).doubleValue(),
|
---|
| 79 | MAXE);
|
---|
| 80 | assertEquals(0, vset2.getUtility(new NumberValue(N09)).doubleValue(),
|
---|
| 81 | MAXE);
|
---|
| 82 |
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | @Test
|
---|
| 86 | public void testMidEqualsHigh() {
|
---|
| 87 | assertEquals(0, vset3.getUtility(new NumberValue(N0)).doubleValue(),
|
---|
| 88 | MAXE);
|
---|
| 89 | assertEquals(0.2, vset3.getUtility(new NumberValue(N01)).doubleValue(),
|
---|
| 90 | MAXE);
|
---|
| 91 | assertEquals(0.2 + 2 * 0.3 / 6,
|
---|
| 92 | vset3.getUtility(new NumberValue(N03)).doubleValue(), MAXE);
|
---|
| 93 | assertEquals(0.5, vset3.getUtility(new NumberValue(N07)).doubleValue(),
|
---|
| 94 | MAXE);
|
---|
| 95 | assertEquals(0, vset3.getUtility(new NumberValue(N09)).doubleValue(),
|
---|
| 96 | MAXE);
|
---|
| 97 |
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | }
|
---|