1 | package geniusweb.boa.biddingstrategy;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertTrue;
|
---|
4 | import static org.mockito.Matchers.any;
|
---|
5 | import static org.mockito.Mockito.mock;
|
---|
6 | import static org.mockito.Mockito.verify;
|
---|
7 | import static org.mockito.Mockito.when;
|
---|
8 |
|
---|
9 | import java.math.BigDecimal;
|
---|
10 | import java.net.URISyntaxException;
|
---|
11 | import java.util.Arrays;
|
---|
12 |
|
---|
13 | import org.junit.Before;
|
---|
14 | import org.junit.Test;
|
---|
15 |
|
---|
16 | import geniusweb.actions.Action;
|
---|
17 | import geniusweb.actions.Offer;
|
---|
18 | import geniusweb.boa.BoaState;
|
---|
19 | import geniusweb.inform.Settings;
|
---|
20 | import geniusweb.issuevalue.Bid;
|
---|
21 | import geniusweb.issuevalue.DiscreteValue;
|
---|
22 | import geniusweb.profile.utilityspace.LinearAdditive;
|
---|
23 | import geniusweb.progress.Progress;
|
---|
24 | import geniusweb.references.Parameters;
|
---|
25 | import tudelft.utilities.immutablelist.FixedList;
|
---|
26 | import tudelft.utilities.immutablelist.ImmutableList;
|
---|
27 | import tudelft.utilities.logging.ReportToLogger;
|
---|
28 |
|
---|
29 | public class TimeDepBidStratTest {
|
---|
30 |
|
---|
31 | // private static final String PROFILE =
|
---|
32 | // "src/test/resources/testprofile.json";
|
---|
33 | // private ProfileRef profileref;
|
---|
34 | private LinearAdditive profile = mock(LinearAdditive.class);
|
---|
35 | private TimeDependentBiddingStrategy biddingstrat;
|
---|
36 | private ExtendedUtilSpace extUtilSpace;
|
---|
37 | private Settings settings = mock(Settings.class);
|
---|
38 | private BoaState state = mock(BoaState.class);
|
---|
39 |
|
---|
40 | private Bid bid1 = new Bid("iss1", new DiscreteValue("val1"));
|
---|
41 | private Bid resBid = new Bid("iss1", new DiscreteValue("val2"));
|
---|
42 | ImmutableList<Bid> alternatives = new FixedList<Bid>(Arrays.asList(bid1));
|
---|
43 |
|
---|
44 | @Before
|
---|
45 | public void before() throws URISyntaxException {
|
---|
46 | when(settings.getParameters()).thenReturn(new Parameters());
|
---|
47 | when(state.getReporter()).thenReturn(new ReportToLogger("test"));
|
---|
48 |
|
---|
49 | biddingstrat = new TimeDependentBiddingStrategy() {
|
---|
50 | @Override
|
---|
51 | protected ExtendedUtilSpace getBidSpace(LinearAdditive profile) {
|
---|
52 | return extUtilSpace;
|
---|
53 | }
|
---|
54 |
|
---|
55 | };
|
---|
56 | // profileref = new ProfileRef(PROFILE);
|
---|
57 |
|
---|
58 | extUtilSpace = mock(ExtendedUtilSpace.class);
|
---|
59 | when(extUtilSpace.getMin()).thenReturn(BigDecimal.ZERO);
|
---|
60 | when(extUtilSpace.getMax()).thenReturn(BigDecimal.ONE);
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Test
|
---|
65 | public void smoke() {
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Test(expected = IllegalArgumentException.class)
|
---|
69 | public void getActionTestNoProfile() {
|
---|
70 | when(state.getSettings()).thenReturn(settings);
|
---|
71 |
|
---|
72 | biddingstrat.getAction(state);
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Test
|
---|
76 | public void getActionAtStart() {
|
---|
77 |
|
---|
78 | when(state.getProfile()).thenReturn(profile);
|
---|
79 | when(state.getSettings()).thenReturn(settings);
|
---|
80 |
|
---|
81 | Progress progress = mock(Progress.class);
|
---|
82 | when(progress.get(any())).thenReturn(0d);
|
---|
83 | // progress = right at start => utilitygoal 1.0
|
---|
84 |
|
---|
85 | when(state.getProgress()).thenReturn(progress);
|
---|
86 | when(extUtilSpace.getBids(any())).thenReturn(alternatives);
|
---|
87 |
|
---|
88 | Action action = biddingstrat.getAction(state);
|
---|
89 |
|
---|
90 | // check that the recommender chose a bid in of utility 1.0
|
---|
91 | verify(extUtilSpace).getBids(BigDecimal.valueOf(1.0));
|
---|
92 | assertTrue(action instanceof Offer);
|
---|
93 | }
|
---|
94 |
|
---|
95 | @Test
|
---|
96 | public void getActionAtHalfway() {
|
---|
97 |
|
---|
98 | when(state.getProfile()).thenReturn(profile);
|
---|
99 | when(state.getSettings()).thenReturn(settings);
|
---|
100 |
|
---|
101 | Progress progress = mock(Progress.class);
|
---|
102 | when(progress.get(any())).thenReturn(0.5d);
|
---|
103 | // progress = halfway => utilitygoal= 0.5
|
---|
104 |
|
---|
105 | when(state.getProgress()).thenReturn(progress);
|
---|
106 | when(extUtilSpace.getBids(any())).thenReturn(alternatives);
|
---|
107 |
|
---|
108 | Action action = biddingstrat.getAction(state);
|
---|
109 |
|
---|
110 | // check that the recommender chose a bid in of utility 1.0
|
---|
111 | verify(extUtilSpace).getBids(BigDecimal.valueOf(0.5));
|
---|
112 | assertTrue(action instanceof Offer);
|
---|
113 | }
|
---|
114 |
|
---|
115 | @Test
|
---|
116 | public void getActionAtEnd() {
|
---|
117 |
|
---|
118 | when(state.getProfile()).thenReturn(profile);
|
---|
119 | when(state.getSettings()).thenReturn(settings);
|
---|
120 |
|
---|
121 | Progress progress = mock(Progress.class);
|
---|
122 | when(progress.get(any())).thenReturn(1d);
|
---|
123 | // progress = end => utilitygoal= 0
|
---|
124 |
|
---|
125 | when(state.getProgress()).thenReturn(progress);
|
---|
126 | when(extUtilSpace.getBids(any())).thenReturn(alternatives);
|
---|
127 |
|
---|
128 | Action action = biddingstrat.getAction(state);
|
---|
129 |
|
---|
130 | // check that the recommender chose a bid in of utility 1.0
|
---|
131 | verify(extUtilSpace).getBids(BigDecimal.valueOf(0.0));
|
---|
132 | assertTrue(action instanceof Offer);
|
---|
133 | }
|
---|
134 |
|
---|
135 | @Test
|
---|
136 | public void getActionAtEndWithReservation() {
|
---|
137 | // if there is reservation bid, it should be considered min
|
---|
138 | when(profile.getReservationBid()).thenReturn(resBid);
|
---|
139 | when(profile.getUtility(resBid)).thenReturn(new BigDecimal("0.5"));
|
---|
140 |
|
---|
141 | when(state.getProfile()).thenReturn(profile);
|
---|
142 | when(state.getSettings()).thenReturn(settings);
|
---|
143 |
|
---|
144 | Progress progress = mock(Progress.class);
|
---|
145 | when(progress.get(any())).thenReturn(1d);
|
---|
146 | // progress = end => utilitygoal= resvalue=0.6
|
---|
147 |
|
---|
148 | when(state.getProgress()).thenReturn(progress);
|
---|
149 | when(extUtilSpace.getBids(any())).thenReturn(alternatives);
|
---|
150 |
|
---|
151 | Action action = biddingstrat.getAction(state);
|
---|
152 |
|
---|
153 | // check that the recommender chose a bid in of utility 0.5
|
---|
154 | verify(extUtilSpace).getBids(BigDecimal.valueOf(0.5));
|
---|
155 | assertTrue(action instanceof Offer);
|
---|
156 | }
|
---|
157 |
|
---|
158 | }
|
---|