source: boa/src/test/java/geniusweb/boa/biddingstrategy/TimeDepBidStratTest.java@ 20

Last change on this file since 20 was 20, checked in by bart, 4 years ago

Added BOA support, some bug fixes

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