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