source: boa/src/test/java/geniusweb/boa/biddingstrategy/TimeDepBidStratTest.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: 4.8 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 geniusweb.references.Parameters;
25import tudelft.utilities.immutablelist.FixedList;
26import tudelft.utilities.immutablelist.ImmutableList;
27import tudelft.utilities.logging.ReportToLogger;
28
29public 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}
Note: See TracBrowser for help on using the repository browser.