source: bidspace/src/test/java/geniusweb/bidspace/pareto/PartialParetoTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 3.9 KB
Line 
1package geniusweb.bidspace.pareto;
2
3import static org.junit.Assert.assertEquals;
4import static org.mockito.Matchers.eq;
5import static org.mockito.Mockito.mock;
6import static org.mockito.Mockito.when;
7
8import java.math.BigDecimal;
9import java.util.Arrays;
10import java.util.HashMap;
11import java.util.HashSet;
12import java.util.Map;
13import java.util.Set;
14
15import org.junit.Before;
16import org.junit.Test;
17
18import geniusweb.issuevalue.Bid;
19import geniusweb.issuevalue.Domain;
20import geniusweb.issuevalue.Value;
21import geniusweb.issuevalue.ValueSet;
22import geniusweb.profile.utilityspace.LinearAdditive;
23
24public class PartialParetoTest {
25 private static final BigDecimal D0_0 = BigDecimal.ZERO;
26 private static final BigDecimal D0_2 = BigDecimal.valueOf(0.2);
27 private static final BigDecimal D0_1 = BigDecimal.valueOf(0.1);
28 private static final BigDecimal D0_3 = BigDecimal.valueOf(0.3);
29 private static final BigDecimal D0_4 = BigDecimal.valueOf(0.4);
30 private static final BigDecimal D0_5 = BigDecimal.valueOf(0.5);
31
32 private final LinearAdditive space1 = mock(LinearAdditive.class),
33 space2 = mock(LinearAdditive.class);
34
35 private Domain domain = mock(Domain.class);
36 private Set<String> issues = new HashSet<String>(
37 Arrays.asList("issue1", "issue2"));
38 private Value value1a = mock(Value.class), value1b = mock(Value.class);
39 private Value value2a = mock(Value.class), value2b = mock(Value.class);
40 private ValueSet issue1valueset = mock(ValueSet.class),
41 issue2valueset = mock(ValueSet.class);
42
43 @Before
44 public void before() {
45 when(value1a.toString()).thenReturn("1A");
46 when(value1b.toString()).thenReturn("1B");
47 when(value2a.toString()).thenReturn("2A");
48 when(value2b.toString()).thenReturn("2B");
49
50 Map<String, Value> map = new HashMap<>();
51 map.put("issue1", value1a);
52 Bid bid10 = new Bid(map);
53 map.put("issue1", value1b);
54 Bid bid20 = new Bid(map);
55
56 map = new HashMap<>();
57 map.put("issue2", value2a);
58 Bid bid01 = new Bid(map);
59 map.put("issue2", value2b);
60 Bid bid02 = new Bid(map);
61
62 when(space1.getUtility(eq(bid10))).thenReturn(D0_1);
63 when(space2.getUtility(eq(bid10))).thenReturn(D0_0);
64
65 when(space1.getUtility(eq(bid20))).thenReturn(D0_2);
66 when(space2.getUtility(eq(bid20))).thenReturn(D0_0);
67
68 when(space1.getUtility(eq(bid01))).thenReturn(D0_0);
69 when(space2.getUtility(eq(bid01))).thenReturn(D0_1);
70
71 when(space1.getUtility(eq(bid02))).thenReturn(D0_0);
72 when(space2.getUtility(eq(bid02))).thenReturn(D0_2);
73
74 when(space1.getDomain()).thenReturn(domain);
75 when(domain.getIssues()).thenReturn(issues);
76 when(issue1valueset.iterator())
77 .thenReturn(Arrays.asList(value1a, value1b).iterator());
78 when(domain.getValues("issue1")).thenReturn(issue1valueset);
79 // by putting the best value first in the list now,
80 // we may trigger a different evaluation path in the PartialPareto
81 // algorithm, improving coverage
82 when(issue2valueset.iterator())
83 .thenReturn(Arrays.asList(value2b, value2a).iterator());
84
85 when(domain.getValues("issue2")).thenReturn(issue2valueset);
86 }
87
88 @Test
89 public void OneIssueTest() {
90 PartialPareto pp = PartialPareto.create(Arrays.asList(space1, space2),
91 Arrays.asList("issue1"));
92 // bid22 is best for both. Check that's the only remaining point
93 assertEquals(1, pp.getPoints().size());
94 Map<String, Value> map = new HashMap<>();
95 map.put("issue1", value1b);
96 // there is no value for issue2 because we asked to exclude it from the
97 // pareto.
98 assertEquals(new Bid(map), pp.getPoints().get(0).getBid());
99
100 }
101
102 @Test
103 public void TwoIssuesTest() {
104 PartialPareto pp = PartialPareto.create(Arrays.asList(space1, space2),
105 Arrays.asList("issue1", "issue2"));
106 // bid22 is best for both. Check that's the only remaining point
107 assertEquals(1, pp.getPoints().size());
108 Map<String, Value> map = new HashMap<>();
109 map.put("issue1", value1b);
110 map.put("issue2", value2b);
111 assertEquals(new Bid(map), pp.getPoints().get(0).getBid());
112
113 }
114}
Note: See TracBrowser for help on using the repository browser.