source: src/test/java/genius/core/uncertainty/UserTest.java

Last change on this file was 242, checked in by Adel Magra, 5 years ago

Updated user guide with information about the User class (sections 1.2, 4.2-3).

File size: 2.9 KB
Line 
1package genius.core.uncertainty;
2
3import static org.junit.Assert.*;
4
5import java.util.List;
6
7import org.junit.Test;
8
9import genius.core.Bid;
10import genius.core.DomainImpl;
11import genius.core.bidding.BidDetails;
12import genius.core.bidding.BidDetailsSorterUtility;
13import genius.core.utility.UncertainAdditiveUtilitySpace;
14import genius.core.uncertainty.UncertainPreferenceContainer;
15import genius.core.uncertainty.UNCERTAINTYTYPE;
16
17public 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}
Note: See TracBrowser for help on using the repository browser.