[43] | 1 | package geniusweb.bidspace.pareto;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 | import static org.junit.Assert.assertFalse;
|
---|
| 5 | import static org.junit.Assert.assertTrue;
|
---|
| 6 | import static org.mockito.Matchers.eq;
|
---|
| 7 | import static org.mockito.Mockito.mock;
|
---|
| 8 | import static org.mockito.Mockito.when;
|
---|
| 9 |
|
---|
| 10 | import java.math.BigDecimal;
|
---|
| 11 | import java.util.Arrays;
|
---|
| 12 | import java.util.HashSet;
|
---|
| 13 |
|
---|
| 14 | import org.junit.Before;
|
---|
| 15 | import org.junit.Test;
|
---|
| 16 |
|
---|
| 17 | import geniusweb.issuevalue.Bid;
|
---|
| 18 | import geniusweb.issuevalue.Value;
|
---|
| 19 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
| 20 |
|
---|
| 21 | public class ParetoPointTest {
|
---|
| 22 | private static final BigDecimal D0_2 = BigDecimal.valueOf(0.2);
|
---|
| 23 | private static final BigDecimal D0_1 = BigDecimal.valueOf(0.1);
|
---|
| 24 | private static final BigDecimal D0_3 = BigDecimal.valueOf(0.3);
|
---|
| 25 | private static final BigDecimal D0_4 = BigDecimal.valueOf(0.4);
|
---|
| 26 | private static final BigDecimal D0_5 = BigDecimal.valueOf(0.5);
|
---|
| 27 | private final LinearAdditive space1 = mock(LinearAdditive.class),
|
---|
| 28 | space2 = mock(LinearAdditive.class);
|
---|
| 29 | private final Bid bid11 = mock(Bid.class), bid12 = mock(Bid.class),
|
---|
| 30 | bid21 = mock(Bid.class), bid22 = mock(Bid.class);
|
---|
| 31 | private ParetoPoint point11, point12, point21, point22;
|
---|
| 32 |
|
---|
| 33 | @Before
|
---|
| 34 | public void before() {
|
---|
| 35 | when(space1.getUtility(eq(bid11))).thenReturn(D0_1);
|
---|
| 36 | when(space2.getUtility(eq(bid11))).thenReturn(D0_1);
|
---|
| 37 |
|
---|
| 38 | when(space1.getUtility(eq(bid12))).thenReturn(D0_1);
|
---|
| 39 | when(space2.getUtility(eq(bid12))).thenReturn(D0_2);
|
---|
| 40 |
|
---|
| 41 | when(space1.getUtility(eq(bid21))).thenReturn(D0_2);
|
---|
| 42 | when(space2.getUtility(eq(bid21))).thenReturn(D0_1);
|
---|
| 43 |
|
---|
| 44 | when(space1.getUtility(eq(bid22))).thenReturn(D0_2);
|
---|
| 45 | when(space2.getUtility(eq(bid22))).thenReturn(D0_2);
|
---|
| 46 |
|
---|
| 47 | point11 = new ParetoPoint(bid11, Arrays.asList(space1, space2));
|
---|
| 48 | point12 = new ParetoPoint(bid12, Arrays.asList(space1, space2));
|
---|
| 49 | point21 = new ParetoPoint(bid21, Arrays.asList(space1, space2));
|
---|
| 50 | point22 = new ParetoPoint(bid22, Arrays.asList(space1, space2));
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | @Test
|
---|
| 54 | public void constructorTest() {
|
---|
| 55 | assertEquals(bid11, point11.getBid());
|
---|
| 56 | assertEquals(bid21, point21.getBid());
|
---|
| 57 |
|
---|
| 58 | assertEquals(Arrays.asList(D0_1, D0_1), point11.getUtilities());
|
---|
| 59 | assertEquals(Arrays.asList(D0_2, D0_1), point21.getUtilities());
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | @Test
|
---|
| 63 | public void dominationTest() {
|
---|
| 64 | assertTrue(point11.isDominatedBy(point11));
|
---|
| 65 | assertTrue(point11.isDominatedBy(point12));
|
---|
| 66 | assertTrue(point11.isDominatedBy(point21));
|
---|
| 67 | assertTrue(point11.isDominatedBy(point22));
|
---|
| 68 |
|
---|
| 69 | assertFalse(point12.isDominatedBy(point11));
|
---|
| 70 | assertFalse(point12.isDominatedBy(point21));
|
---|
| 71 | assertTrue(point12.isDominatedBy(point12));
|
---|
| 72 | assertTrue(point12.isDominatedBy(point22));
|
---|
| 73 |
|
---|
| 74 | assertFalse(point21.isDominatedBy(point11));
|
---|
| 75 | assertFalse(point21.isDominatedBy(point12));
|
---|
| 76 | assertTrue(point21.isDominatedBy(point21));
|
---|
| 77 | assertTrue(point21.isDominatedBy(point22));
|
---|
| 78 |
|
---|
| 79 | assertFalse(point22.isDominatedBy(point11));
|
---|
| 80 | assertFalse(point22.isDominatedBy(point12));
|
---|
| 81 | assertFalse(point22.isDominatedBy(point21));
|
---|
| 82 | assertTrue(point22.isDominatedBy(point22));
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | @Test
|
---|
| 86 | public void mergeTest() {
|
---|
| 87 | // partial bid 020_010 has value 0.2 for issue 2 in space1 and 0.1 for
|
---|
| 88 | // issue 2 in space2.
|
---|
| 89 | Bid partialbid020_010 = mock(Bid.class),
|
---|
| 90 | partialbid102_301 = mock(Bid.class);
|
---|
| 91 | // merged this should be a bid 122_311 so it has utilities
|
---|
| 92 | // 1+2+2=0.5 in space1 and 3+1+1=0.5 in space2
|
---|
| 93 |
|
---|
| 94 | when(partialbid020_010.getIssues())
|
---|
| 95 | .thenReturn(new HashSet<String>(Arrays.asList("issue2")));
|
---|
| 96 | when(partialbid102_301.getIssues()).thenReturn(
|
---|
| 97 | new HashSet<String>(Arrays.asList("issue1", "issue3")));
|
---|
| 98 |
|
---|
| 99 | Value value1 = mock(Value.class), value2 = mock(Value.class),
|
---|
| 100 | value3 = mock(Value.class);
|
---|
| 101 | when(partialbid020_010.getValue(eq("issue2"))).thenReturn(value2);
|
---|
| 102 | when(partialbid102_301.getValue(eq("issue1"))).thenReturn(value1);
|
---|
| 103 | when(partialbid102_301.getValue(eq("issue3"))).thenReturn(value3);
|
---|
| 104 |
|
---|
| 105 | when(space1.getUtility(eq(partialbid020_010))).thenReturn(D0_2);
|
---|
| 106 | when(space1.getUtility(eq(partialbid102_301))).thenReturn(D0_3);
|
---|
| 107 | when(space2.getUtility(eq(partialbid020_010))).thenReturn(D0_1);
|
---|
| 108 | when(space2.getUtility(eq(partialbid102_301))).thenReturn(D0_4);
|
---|
| 109 |
|
---|
| 110 | ParetoPoint p1 = new ParetoPoint(partialbid020_010,
|
---|
| 111 | Arrays.asList(space1, space2));
|
---|
| 112 | ParetoPoint p2 = new ParetoPoint(partialbid102_301,
|
---|
| 113 | Arrays.asList(space1, space2));
|
---|
| 114 |
|
---|
| 115 | ParetoPoint p = p1.merge(p2);
|
---|
| 116 | Bid bid = p.getBid();
|
---|
| 117 | assertEquals(
|
---|
| 118 | new HashSet<String>(
|
---|
| 119 | Arrays.asList("issue1", "issue2", "issue3")),
|
---|
| 120 | bid.getIssues());
|
---|
| 121 | assertEquals(value1, bid.getValue("issue1"));
|
---|
| 122 | assertEquals(value2, bid.getValue("issue2"));
|
---|
| 123 | assertEquals(value3, bid.getValue("issue3"));
|
---|
| 124 | assertEquals(D0_5, p.getUtilities().get(0));
|
---|
| 125 | assertEquals(D0_5, p.getUtilities().get(1));
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | }
|
---|