source: anac2020/AzarAgent/src/test/java/geniusweb/exampleparties/simpleshaop/SimpleLinearOrderingTest.java@ 31

Last change on this file since 31 was 1, checked in by wouter, 4 years ago

#1910 added anac2020 parties

File size: 3.5 KB
Line 
1package geniusweb.exampleparties.simpleshaop;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5import static org.mockito.Mockito.mock;
6import static org.mockito.Mockito.when;
7
8import java.math.BigDecimal;
9import java.util.Arrays;
10import java.util.Collections;
11import java.util.List;
12
13import org.junit.Before;
14import org.junit.Test;
15
16import geniusweb.issuevalue.Bid;
17import geniusweb.issuevalue.Domain;
18import geniusweb.profile.DefaultPartialOrdering;
19
20public class SimpleLinearOrderingTest {
21 private DefaultPartialOrdering realprofile = mock(
22 DefaultPartialOrdering.class);;
23 private Domain domain = mock(Domain.class);
24 private SimpleLinearOrdering estprofile;
25 private Bid bid1 = makeBid(1);
26 private Bid bid2 = makeBid(2);
27 private Bid bid3 = makeBid(3);
28 private Bid bid4 = makeBid(4);
29 private final List<Bid> emptyList = Collections.emptyList();
30
31 @Before
32 public void before() {
33 when(realprofile.getDomain()).thenReturn(domain);
34 estprofile = new SimpleLinearOrdering(realprofile);
35 when(bid1.toString()).thenReturn("bid1");
36
37 }
38
39 private static Bid makeBid(int n) {
40 Bid mockbid = mock(Bid.class);
41 when(mockbid.toString()).thenReturn("bid " + n);
42 return mockbid;
43 }
44
45 @Test
46 public void testSmoke() {
47 }
48
49 @Test
50 public void testInitialBids() {
51 assertTrue(estprofile.getBids().isEmpty());
52 }
53
54 @Test
55 public void largerInitialListTest() {
56 when(realprofile.getBids()).thenReturn(Arrays.asList(bid1, bid2, bid3));
57 // idea is that 3 > 2 > 1
58 when(realprofile.isPreferredOrEqual(bid2, bid1)).thenReturn(true);
59 when(realprofile.isPreferredOrEqual(bid1, bid2)).thenReturn(false);
60 when(realprofile.isPreferredOrEqual(bid3, bid2)).thenReturn(true);
61 when(realprofile.isPreferredOrEqual(bid2, bid3)).thenReturn(false);
62 when(realprofile.isPreferredOrEqual(bid3, bid1)).thenReturn(true);
63 when(realprofile.isPreferredOrEqual(bid1, bid3)).thenReturn(false);
64 SimpleLinearOrdering testprofile = new SimpleLinearOrdering(
65 realprofile);
66 assertEquals(Arrays.asList(bid1, bid2, bid3), testprofile.getBids());
67 }
68
69 @Test
70 public void testAddFirstBid() {
71 SimpleLinearOrdering prof1 = estprofile.with(bid1,
72 Collections.emptyList());
73
74 assertEquals(1, prof1.getBids().size());
75 }
76
77 @Test
78 public void testAddTwoBidsSecondIsWorse() {
79 SimpleLinearOrdering prof1 = estprofile.with(bid1, emptyList);
80 // new bid is worse as bid1, so list of worse bids is empty
81 SimpleLinearOrdering prof2 = prof1.with(bid2, emptyList);
82
83 assertEquals(Arrays.asList(bid2, bid1), prof2.getBids());
84 }
85
86 @Test
87 public void testAddTwoBidsSecondIsBetter() {
88 SimpleLinearOrdering prof1 = estprofile.with(bid1, emptyList);
89 SimpleLinearOrdering prof2 = prof1.with(bid2, Arrays.asList(bid1));
90
91 assertEquals(Arrays.asList(bid1, bid2), prof2.getBids());
92 }
93
94 @Test
95 public void testAddThreeBidsThirdIsMiddle() {
96 SimpleLinearOrdering prof1 = new SimpleLinearOrdering(domain,
97 Arrays.asList(bid1, bid2));
98 SimpleLinearOrdering prof2 = prof1.with(bid3, Arrays.asList(bid1));
99
100 assertEquals(Arrays.asList(bid1, bid3, bid2), prof2.getBids());
101 }
102
103 @Test
104 public void getUtilityTest3Bids() {
105 SimpleLinearOrdering prof1 = new SimpleLinearOrdering(domain,
106 Arrays.asList(bid1, bid3, bid2));
107
108 assertEquals(new BigDecimal("0.50000000"), prof1.getUtility(bid3));
109 }
110
111 @Test
112 public void getUtilityTest4Bids() {
113 // with 4 bids, we get utility 1/3 which causes deximal expansiion issue
114 SimpleLinearOrdering prof1 = new SimpleLinearOrdering(domain,
115 Arrays.asList(bid1, bid2, bid3, bid4));
116
117 assertEquals(new BigDecimal("0.33333333"), prof1.getUtility(bid2));
118 }
119
120}
Note: See TracBrowser for help on using the repository browser.