1 | package geniusweb.profile.opponentmodel;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 | import static org.junit.Assert.assertTrue;
|
---|
5 | import static org.mockito.Mockito.mock;
|
---|
6 |
|
---|
7 | import java.math.BigDecimal;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.HashMap;
|
---|
11 | import java.util.LinkedList;
|
---|
12 | import java.util.List;
|
---|
13 | import java.util.Map;
|
---|
14 |
|
---|
15 | import org.junit.Test;
|
---|
16 |
|
---|
17 | import geniusweb.actions.Offer;
|
---|
18 | import geniusweb.actions.PartyId;
|
---|
19 | import geniusweb.issuevalue.Bid;
|
---|
20 | import geniusweb.issuevalue.DiscreteValue;
|
---|
21 | import geniusweb.issuevalue.DiscreteValueSet;
|
---|
22 | import geniusweb.issuevalue.Domain;
|
---|
23 | import geniusweb.issuevalue.NumberValue;
|
---|
24 | import geniusweb.issuevalue.NumberValueSet;
|
---|
25 | import geniusweb.issuevalue.Value;
|
---|
26 | import geniusweb.issuevalue.ValueSet;
|
---|
27 | import geniusweb.opponentmodel.FrequencyOpponentModel;
|
---|
28 | import geniusweb.progress.Progress;
|
---|
29 | import tudelft.utilities.junit.GeneralTests;
|
---|
30 |
|
---|
31 | public class FrequencyOppModelTest
|
---|
32 | extends GeneralTests<FrequencyOpponentModel> {
|
---|
33 | private final static String ISS1 = "issue1";
|
---|
34 | private final static String ISS2 = "issue2";
|
---|
35 | private static final DiscreteValue I1V1 = new DiscreteValue("i1v1");
|
---|
36 | private static final DiscreteValue I1V2 = new DiscreteValue("i1v2");
|
---|
37 | private static final DiscreteValue I1V2b = new DiscreteValue("i1v2b");
|
---|
38 | private static final Progress progress = mock(Progress.class);
|
---|
39 | private static final PartyId other = new PartyId("other");
|
---|
40 |
|
---|
41 | private static Domain domain, domain2, domain3;
|
---|
42 | private static FrequencyOpponentModel oppModel1, oppModel1b, oppModel2,
|
---|
43 | oppModel3, oppModel4;
|
---|
44 |
|
---|
45 | private final static List<List<Bid>> list = new LinkedList<>();
|
---|
46 |
|
---|
47 | private final static Bid bid1, bid2, bid3;
|
---|
48 | private static final BigDecimal HALF = new BigDecimal("0.5");
|
---|
49 |
|
---|
50 | static {
|
---|
51 | Map<String, ValueSet> issues = new HashMap<>();
|
---|
52 | Collection<DiscreteValue> discretevalues1 = new LinkedList<>();
|
---|
53 | discretevalues1.add(I1V1);
|
---|
54 | discretevalues1.add(I1V2);
|
---|
55 | DiscreteValueSet values1 = new DiscreteValueSet(discretevalues1);
|
---|
56 | issues.put(ISS1, values1);
|
---|
57 | NumberValueSet values2 = new NumberValueSet(BigDecimal.ZERO,
|
---|
58 | BigDecimal.TEN, new BigDecimal("0.3"));
|
---|
59 | issues.put(ISS2, values2);
|
---|
60 | domain = new Domain("test", issues);
|
---|
61 | domain2 = new Domain("test2", issues);
|
---|
62 |
|
---|
63 | // slightly different issue1
|
---|
64 | issues = new HashMap<>();
|
---|
65 | discretevalues1 = new LinkedList<>();
|
---|
66 | discretevalues1.add(I1V1);
|
---|
67 | discretevalues1.add(I1V2b);
|
---|
68 | values1 = new DiscreteValueSet(discretevalues1);
|
---|
69 | issues.put(ISS1, values1);
|
---|
70 | values2 = new NumberValueSet(BigDecimal.ZERO, BigDecimal.TEN,
|
---|
71 | new BigDecimal("0.3"));
|
---|
72 | issues.put(ISS2, values2);
|
---|
73 | domain3 = new Domain("test", issues);
|
---|
74 |
|
---|
75 | // all bids are for domain
|
---|
76 | Map<String, Value> issuevalues = new HashMap<>();
|
---|
77 | issuevalues.put(ISS1, I1V1);
|
---|
78 | issuevalues.put(ISS2, new NumberValue(new BigDecimal("1.2")));
|
---|
79 | bid1 = new Bid(issuevalues);
|
---|
80 |
|
---|
81 | issuevalues.put(ISS1, I1V1);
|
---|
82 | issuevalues.put(ISS2, new NumberValue(new BigDecimal("1.5")));
|
---|
83 | bid2 = new Bid(issuevalues);
|
---|
84 |
|
---|
85 | issuevalues.put(ISS1, I1V2);
|
---|
86 | issuevalues.put(ISS2, new NumberValue(new BigDecimal("1.5")));
|
---|
87 | bid3 = new Bid(issuevalues);
|
---|
88 |
|
---|
89 | oppModel1 = new FrequencyOpponentModel().with(domain, null);
|
---|
90 | oppModel1b = new FrequencyOpponentModel().with(domain, null);
|
---|
91 | oppModel2 = new FrequencyOpponentModel().with(domain2, null);
|
---|
92 | oppModel3 = new FrequencyOpponentModel().with(domain3, null);
|
---|
93 | oppModel4 = oppModel3.with(new Offer(other, bid1), progress);
|
---|
94 |
|
---|
95 | }
|
---|
96 |
|
---|
97 | @Override
|
---|
98 | public List<List<FrequencyOpponentModel>> getGeneralTestData() {
|
---|
99 | return Arrays.asList(Arrays.asList(oppModel1, oppModel1b),
|
---|
100 | Arrays.asList(oppModel2), Arrays.asList(oppModel3),
|
---|
101 | Arrays.asList(oppModel4));
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Override
|
---|
105 | public List<String> getGeneralTestStrings() {
|
---|
106 | return Arrays.asList(
|
---|
107 | "FrequencyOpponentModel\\[0,\\{issue2=\\{\\}, issue1=\\{\\}\\}\\]",
|
---|
108 | "FrequencyOpponentModel\\[0,\\{issue2=\\{\\}, issue1=\\{\\}\\}\\]",
|
---|
109 | "FrequencyOpponentModel\\[0,\\{issue2=\\{\\}, issue1=\\{\\}\\}\\]",
|
---|
110 | "FrequencyOpponentModel\\[1,\\{issue2=\\{1.2=1\\}, issue1=\\{\"i1v1\"=1\\}\\}\\]");
|
---|
111 | }
|
---|
112 |
|
---|
113 | @Test(expected = NullPointerException.class)
|
---|
114 | public void smokeTestNull() {
|
---|
115 | new FrequencyOpponentModel().with((Domain) null, null);
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test
|
---|
119 | public void smokeTest() {
|
---|
120 | new FrequencyOpponentModel().with(domain, null);
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Test
|
---|
124 | public void testEmptyModel() {
|
---|
125 | FrequencyOpponentModel oppModel = new FrequencyOpponentModel()
|
---|
126 | .with(domain, null);
|
---|
127 | assertEquals(BigDecimal.ONE, oppModel.getUtility(bid1));
|
---|
128 | assertEquals(BigDecimal.ONE, oppModel.getUtility(bid2));
|
---|
129 | }
|
---|
130 |
|
---|
131 | @Test
|
---|
132 | public void testUpdate() {
|
---|
133 | FrequencyOpponentModel oppModel = oppModel1.with(new Offer(other, bid1),
|
---|
134 | progress);
|
---|
135 | assertTrue(BigDecimal.ONE.compareTo(oppModel.getUtility(bid1)) == 0);
|
---|
136 | assertTrue(BigDecimal.ZERO.compareTo(oppModel.getUtility(bid3)) == 0);
|
---|
137 | // bid2 has 1 of 2 issue values same as bid1.
|
---|
138 | assertTrue(HALF.compareTo(oppModel.getUtility(bid2)) == 0);
|
---|
139 | }
|
---|
140 |
|
---|
141 | @Test
|
---|
142 | public void testUpdate2() {
|
---|
143 | // bid1 and bid2 both want I1V1. They differ on the number value.
|
---|
144 | // bid3 wants I1V2 but does have the number value from bid2
|
---|
145 | FrequencyOpponentModel oppModel = oppModel1
|
---|
146 | .with(new Offer(other, bid1), progress)
|
---|
147 | .with(new Offer(other, bid2), progress);
|
---|
148 | assertTrue(new BigDecimal("0.75")
|
---|
149 | .compareTo(oppModel.getUtility(bid1)) == 0);
|
---|
150 | assertTrue(new BigDecimal("0.75")
|
---|
151 | .compareTo(oppModel.getUtility(bid2)) == 0);
|
---|
152 | assertTrue(new BigDecimal("0.25")
|
---|
153 | .compareTo(oppModel.getUtility(bid3)) == 0);
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Test
|
---|
157 | public void testPartialBidUpdate() {
|
---|
158 | FrequencyOpponentModel oppModel = oppModel1.with(new Offer(other, bid1),
|
---|
159 | progress);
|
---|
160 | Bid partialbid = new Bid(ISS1, I1V1);
|
---|
161 | oppModel.with(new Offer(other, partialbid), progress);
|
---|
162 | }
|
---|
163 |
|
---|
164 | }
|
---|