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