source: geniuswebcore/test/geniusweb/bidspace/pareto/ParetoPointTest.py@ 94

Last change on this file since 94 was 90, checked in by Bart Vastenhouw, 3 years ago

Refactor to help reusing partiesserver.

File size: 3.4 KB
Line 
1from decimal import Decimal
2import unittest
3from unittest.mock import Mock
4
5from geniusweb.bidspace.pareto.ParetoPoint import ParetoPoint
6from geniusweb.issuevalue.Bid import Bid
7from geniusweb.issuevalue.Value import Value
8from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive
9
10
11class ParetoPointTest(unittest.TestCase):
12 D0_2 = Decimal("0.2")
13 D0_1 = Decimal("0.1")
14 D0_3 = Decimal("0.3")
15 D0_4 = Decimal("0.4")
16 D0_5 = Decimal("0.5")
17 space1 = Mock(LinearAdditive)
18 space2 = Mock(LinearAdditive)
19 bid11 = Mock(Bid)
20 bid12 = Mock(Bid)
21 bid21 = Mock(Bid)
22 bid22 = Mock(Bid)
23
24 def setUp(self):
25 self.space1.getUtility = Mock(side_effect=lambda b: \
26 {self.bid11:self.D0_1, self.bid12:self.D0_1, \
27 self.bid21:self.D0_2, self.bid22:self.D0_2 }[b])
28 self.space2.getUtility = Mock(side_effect=lambda b: \
29 {self.bid11:self.D0_1, self.bid12:self.D0_2, \
30 self.bid21:self.D0_1, self.bid22:self.D0_2 }[b])
31
32 self.point11 = ParetoPoint.create(self.bid11, [self.space1, self.space2])
33 self.point12 = ParetoPoint.create(self.bid12, [self.space1, self.space2])
34 self.point21 = ParetoPoint.create(self.bid21, [self.space1, self.space2])
35 self.point22 = ParetoPoint.create(self.bid22, [self.space1, self.space2])
36
37 def testconstructorTest(self):
38 self.assertEqual(self.bid11, self.point11.getBid())
39 self.assertEqual(self.bid21, self.point21.getBid())
40
41 self.assertEqual([self.D0_1, self.D0_1], self.point11.getUtilities())
42 self.assertEqual([self.D0_2, self.D0_1], self.point21.getUtilities())
43
44 def testdominationTest(self):
45 self.assertTrue(self.point11.isDominatedBy(self.point11))
46 self.assertTrue(self.point11.isDominatedBy(self.point12))
47 self.assertTrue(self.point11.isDominatedBy(self.point21))
48 self.assertTrue(self.point11.isDominatedBy(self.point22))
49
50 self.assertFalse(self.point12.isDominatedBy(self.point11))
51 self.assertFalse(self.point12.isDominatedBy(self.point21))
52 self.assertTrue(self.point12.isDominatedBy(self.point12))
53 self.assertTrue(self.point12.isDominatedBy(self.point22))
54
55 self.assertFalse(self.point21.isDominatedBy(self.point11))
56 self.assertFalse(self.point21.isDominatedBy(self.point12))
57 self.assertTrue(self.point21.isDominatedBy(self.point21))
58 self.assertTrue(self.point21.isDominatedBy(self.point22))
59
60 self.assertFalse(self.point22.isDominatedBy(self.point11))
61 self.assertFalse(self.point22.isDominatedBy(self.point12))
62 self.assertFalse(self.point22.isDominatedBy(self.point21))
63 self.assertTrue(self.point22.isDominatedBy(self.point22))
64
65 def testmergeTest(self):
66 # partial bid 020_010 has value 0.2 for issue 2 in space1 and 0.1 for
67 # issue 2 in space2.
68 value1 = Mock(Value)
69 value2 = Mock(Value)
70 value3 = Mock(Value)
71
72 partialbid020_010 = Bid({"issue2": value2})
73 partialbid102_301 = Bid({"issue1": value1, "issue3":value3})
74 # merged this should be a bid 122_311 so it has utilities
75 # 1+2+2=0.5 in space1 and 3+1+1=0.5 in space2
76
77 self.space1.getUtility = Mock(side_effect=lambda bid:\
78 {partialbid020_010:self.D0_2, partialbid102_301:self.D0_3}[bid])
79 self.space2.getUtility = Mock(side_effect=lambda bid:
80 {partialbid020_010:self.D0_1, partialbid102_301:self.D0_4 }[bid])
81
82 p1 = ParetoPoint.create(partialbid020_010, [self.space1, self.space2])
83 p2 = ParetoPoint.create(partialbid102_301, [self.space1, self.space2])
84
85 p = p1.merge(p2)
86 bid = p.getBid()
87 self.assertEqual(self.D0_5, p.getUtilities()[0])
88 self.assertEqual(self.D0_5, p.getUtilities()[1])
Note: See TracBrowser for help on using the repository browser.