source: boa/src/test/java/geniusweb/boa/acceptancestrategy/TimeDepAccStratTest.java@ 31

Last change on this file since 31 was 31, checked in by bart, 3 years ago

New protocols Learn and APPLearn. Fixed memory leak.

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