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

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

Version 1.5.

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.inform.Settings;
20import geniusweb.issuevalue.Bid;
21import geniusweb.issuevalue.DiscreteValue;
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 @Override
49 protected ExtendedUtilSpace getBidSpace(LinearAdditive profile) {
50 return extUtilSpace;
51 }
52
53 };
54 // profileref = new ProfileRef(PROFILE);
55
56 extUtilSpace = mock(ExtendedUtilSpace.class);
57 when(extUtilSpace.getMin()).thenReturn(BigDecimal.ZERO);
58 when(extUtilSpace.getMax()).thenReturn(BigDecimal.ONE);
59
60 }
61
62 @Test
63 public void smoke() {
64 }
65
66 @Test(expected = IllegalArgumentException.class)
67 public void getActionTestNoProfile() {
68 when(state.getSettings()).thenReturn(settings);
69
70 biddingstrat.getAction(state);
71 }
72
73 @Test
74 public void getActionAtStart() {
75
76 when(state.getProfile()).thenReturn(profile);
77 when(state.getSettings()).thenReturn(settings);
78
79 Progress progress = mock(Progress.class);
80 when(progress.get(any())).thenReturn(0d);
81 // progress = right at start => utilitygoal 1.0
82
83 when(state.getProgress()).thenReturn(progress);
84 when(extUtilSpace.getBids(any())).thenReturn(alternatives);
85
86 Action action = biddingstrat.getAction(state);
87
88 // check that the recommender chose a bid in of utility 1.0
89 verify(extUtilSpace).getBids(BigDecimal.valueOf(1.0));
90 assertTrue(action instanceof Offer);
91 }
92
93 @Test
94 public void getActionAtHalfway() {
95
96 when(state.getProfile()).thenReturn(profile);
97 when(state.getSettings()).thenReturn(settings);
98
99 Progress progress = mock(Progress.class);
100 when(progress.get(any())).thenReturn(0.5d);
101 // progress = halfway => utilitygoal= 0.5
102
103 when(state.getProgress()).thenReturn(progress);
104 when(extUtilSpace.getBids(any())).thenReturn(alternatives);
105
106 Action action = biddingstrat.getAction(state);
107
108 // check that the recommender chose a bid in of utility 1.0
109 verify(extUtilSpace).getBids(BigDecimal.valueOf(0.5));
110 assertTrue(action instanceof Offer);
111 }
112
113 @Test
114 public void getActionAtEnd() {
115
116 when(state.getProfile()).thenReturn(profile);
117 when(state.getSettings()).thenReturn(settings);
118
119 Progress progress = mock(Progress.class);
120 when(progress.get(any())).thenReturn(1d);
121 // progress = end => utilitygoal= 0
122
123 when(state.getProgress()).thenReturn(progress);
124 when(extUtilSpace.getBids(any())).thenReturn(alternatives);
125
126 Action action = biddingstrat.getAction(state);
127
128 // check that the recommender chose a bid in of utility 1.0
129 verify(extUtilSpace).getBids(BigDecimal.valueOf(0.0));
130 assertTrue(action instanceof Offer);
131 }
132
133 @Test
134 public void getActionAtEndWithReservation() {
135 // if there is reservation bid, it should be considered min
136 when(profile.getReservationBid()).thenReturn(resBid);
137 when(profile.getUtility(resBid)).thenReturn(new BigDecimal("0.5"));
138
139 when(state.getProfile()).thenReturn(profile);
140 when(state.getSettings()).thenReturn(settings);
141
142 Progress progress = mock(Progress.class);
143 when(progress.get(any())).thenReturn(1d);
144 // progress = end => utilitygoal= resvalue=0.6
145
146 when(state.getProgress()).thenReturn(progress);
147 when(extUtilSpace.getBids(any())).thenReturn(alternatives);
148
149 Action action = biddingstrat.getAction(state);
150
151 // check that the recommender chose a bid in of utility 0.5
152 verify(extUtilSpace).getBids(BigDecimal.valueOf(0.5));
153 assertTrue(action instanceof Offer);
154 }
155
156}
Note: See TracBrowser for help on using the repository browser.