source: boa/src/test/java/geniusweb/boa/acceptancestrategy/TimeDepAccStratTest.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.6 KB
Line 
1package geniusweb.boa.acceptancestrategy;
2
3import static org.junit.Assert.assertFalse;
4import static org.junit.Assert.assertTrue;
5import static org.mockito.Matchers.any;
6import static org.mockito.Matchers.eq;
7import static org.mockito.Mockito.mock;
8import static org.mockito.Mockito.when;
9
10import java.math.BigDecimal;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import geniusweb.actions.Accept;
16import geniusweb.actions.Offer;
17import geniusweb.actions.PartyId;
18import geniusweb.bidspace.BidsWithUtility;
19import geniusweb.bidspace.Interval;
20import geniusweb.boa.BoaState;
21import geniusweb.inform.Settings;
22import geniusweb.issuevalue.Bid;
23import geniusweb.profile.Profile;
24import geniusweb.profile.utilityspace.LinearAdditive;
25import geniusweb.progress.Progress;
26import geniusweb.progress.ProgressRounds;
27import geniusweb.references.Parameters;
28
29public class TimeDepAccStratTest {
30 private static final Bid resbid = mock(Bid.class);
31 private final Progress progress = mock(ProgressRounds.class);
32 private final BidsWithUtility testbidspace = mock(BidsWithUtility.class);
33 private final BoaState state = mock(BoaState.class);
34 private final Bid bid1 = mock(Bid.class);
35 private final Settings settings = mock(Settings.class);
36 private final LinearAdditive linearprofile = mock(LinearAdditive.class);
37 private PartyId party = new PartyId("someparty");
38
39 @Before
40 public void before() {
41 when(state.getSettings()).thenReturn(settings);
42 when(state.getProfile()).thenReturn(linearprofile);
43 when(state.getProgress()).thenReturn(progress);
44 when(settings.getParameters()).thenReturn(new Parameters());
45
46 }
47
48 @Test
49 public void testRoundsProgressAtStart() {
50 when(testbidspace.getRange())
51 .thenReturn(new Interval(BigDecimal.ZERO, BigDecimal.ONE));
52
53 TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
54 @Override
55 protected BidsWithUtility getBidspace(Profile profile) {
56 return testbidspace;
57 }
58 };
59 // we use default e=1, k=0 which means p(0)=1
60
61 when(progress.get(any())).thenReturn(0.0d);
62
63 when(linearprofile.getUtility(eq(bid1)))
64 .thenReturn(BigDecimal.valueOf(0.4));
65
66 assertFalse(ac.filter(new Offer(party, bid1), state) instanceof Accept);
67 }
68
69 @Test
70 public void testRoundsProgressAtStart1() {
71 when(testbidspace.getRange()).thenReturn(
72 new Interval(BigDecimal.ZERO, new BigDecimal("0.4")));
73 // the max util in this space is 0.4
74
75 TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
76 @Override
77 protected BidsWithUtility getBidspace(Profile profile) {
78 return testbidspace;
79 }
80 };
81 // we use default e=1, k=0 which means p(0)=1
82
83 when(progress.get(any())).thenReturn(0.0d);
84
85 when(linearprofile.getUtility(eq(bid1)))
86 .thenReturn(new BigDecimal("0.4")); // now =max util
87 when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
88 assertTrue(ac.filter(new Offer(party, bid1), state) instanceof Accept);
89 }
90
91 @Test
92 public void testRoundsProgressAtEnd() {
93 when(testbidspace.getRange())
94 .thenReturn(new Interval(BigDecimal.ZERO, BigDecimal.ONE));
95
96 TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
97 @Override
98 protected BidsWithUtility getBidspace(Profile profile) {
99 return testbidspace;
100 }
101 };
102 // we use default e=1, k=0 which means p(1)=0
103
104 when(progress.get(any())).thenReturn(1.0d);
105
106 when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
107 when(linearprofile.getUtility(eq(bid1)))
108 .thenReturn(BigDecimal.valueOf(0.4));
109
110 when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
111 assertTrue(ac.filter(new Offer(party, bid1), state) instanceof Accept);
112 }
113
114 @Test
115 public void testRoundsProgressResValueIsUsed() {
116 // resbid should raise the minimum at the end.
117 // we check that at the end a bid with lower util than resbid is
118 // not accepted.
119 when(testbidspace.getRange())
120 .thenReturn(new Interval(BigDecimal.ZERO, BigDecimal.ONE));
121
122 TimeDependentAcceptanceStrategy ac = new TimeDependentAcceptanceStrategy() {
123 @Override
124 protected BidsWithUtility getBidspace(Profile profile) {
125 return testbidspace;
126 }
127 };
128 // we use default e=1, k=0 which means p(1)=resValue.
129
130 when(progress.get(any())).thenReturn(1.0d);
131
132 when(linearprofile.getUtility(eq(bid1)))
133 .thenReturn(BigDecimal.valueOf(0.4));
134
135 when(linearprofile.getReservationBid()).thenReturn(resbid);
136 when(linearprofile.getUtility(eq(resbid)))
137 .thenReturn(new BigDecimal("0.5"));
138
139 // bid1 has util 0.4 which is below res value.
140 when(state.getLastReceivedOffer()).thenReturn(new Offer(party, bid1));
141 assertFalse(ac.filter(new Offer(party, bid1), state) instanceof Accept);
142 }
143
144}
Note: See TracBrowser for help on using the repository browser.