1 | package genius.core.uncertainty;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.*;
|
---|
4 |
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import org.junit.Test;
|
---|
8 |
|
---|
9 | import genius.core.Bid;
|
---|
10 | import genius.core.DomainImpl;
|
---|
11 | import genius.core.bidding.BidDetails;
|
---|
12 | import genius.core.bidding.BidDetailsSorterUtility;
|
---|
13 | import genius.core.utility.UncertainAdditiveUtilitySpace;
|
---|
14 | import genius.core.uncertainty.UncertainPreferenceContainer;
|
---|
15 | import genius.core.uncertainty.UNCERTAINTYTYPE;
|
---|
16 |
|
---|
17 | public class UserTest {
|
---|
18 |
|
---|
19 | String PARTY = "src/test/resources/partydomain/";
|
---|
20 |
|
---|
21 | @Test
|
---|
22 | public void testElicitBidAndAll() throws Exception {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * We start by creating a user and a user model for the party1_utility space.
|
---|
26 | */
|
---|
27 | DomainImpl domain = new DomainImpl(PARTY + "party_domain.xml");
|
---|
28 | UncertainAdditiveUtilitySpace utilSpace = new UncertainAdditiveUtilitySpace(domain,
|
---|
29 | PARTY + "party1_utility.xml");
|
---|
30 | User user = new User(utilSpace);
|
---|
31 | UncertainPreferenceContainer u = new UncertainPreferenceContainer(utilSpace, UNCERTAINTYTYPE.PAIRWISECOMP);
|
---|
32 | UserModel userModel = u.getPairwiseCompUserModel();
|
---|
33 | BidRanking bidRank = userModel.getBidRanking();
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Here, we begin the testing of the core function elicitBid.
|
---|
37 | */
|
---|
38 | int originalSize = bidRank.getSize();
|
---|
39 | Bid maxBid = bidRank.getMaximalBid();
|
---|
40 | UserModel updated = user.elicitRank(maxBid, userModel);
|
---|
41 |
|
---|
42 | //Should stay the same because maxBid is already in userModel.
|
---|
43 | assertEquals(updated, userModel);
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Obtain a random bid not in the user model and add it to updated.
|
---|
47 | * We first test that it was indeed added.
|
---|
48 | * Then we test that it is at the right place in the ranking.
|
---|
49 | */
|
---|
50 | Bid bid = maxBid;
|
---|
51 | while(bidRank.getBidOrder().contains(bid))
|
---|
52 | bid = domain.getRandomBid(null);
|
---|
53 | updated = user.elicitRank(bid, userModel);
|
---|
54 | assertEquals((originalSize + 1), updated.getBidRanking().getSize());
|
---|
55 | int bidIndex = updated.getBidRanking().indexOf(bid);
|
---|
56 | Bid prevBid = updated.getBidRanking().getBidOrder().get(bidIndex-1);
|
---|
57 | Bid nextBid = updated.getBidRanking().getBidOrder().get(bidIndex+1);
|
---|
58 | BidDetails prev = new BidDetails(prevBid, utilSpace.getUtility(prevBid));
|
---|
59 | BidDetails next = new BidDetails(nextBid, utilSpace.getUtility(nextBid));
|
---|
60 | BidDetails newBid = new BidDetails(bid, utilSpace.getUtility(bid));
|
---|
61 | int comparResult = (new BidDetailsSorterUtility()).compare(prev, newBid);
|
---|
62 | assertEquals(comparResult, 1);
|
---|
63 | comparResult = (new BidDetailsSorterUtility()).compare(newBid, next);
|
---|
64 | assertEquals(comparResult,1);
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Now we check that the updated ranking without new bid is the same as the old ranking.
|
---|
68 | */
|
---|
69 | List<Bid> updatedWithoutBid = updated.getBidRanking().getBidOrder();
|
---|
70 | updatedWithoutBid.remove(bidIndex);
|
---|
71 | assertEquals(updatedWithoutBid, bidRank.getBidOrder());
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * We finally test that the total bother was well updated.
|
---|
75 | */
|
---|
76 | double elicitationCost = utilSpace.getElicitationCost();
|
---|
77 | assertEquals(elicitationCost,user.getTotalBother(),0.00000000001);
|
---|
78 |
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|