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