source: geniuswebcore/test/geniusweb/profile/utilityspace/DiscreteValSetUtilsTest.py@ 99

Last change on this file since 99 was 96, checked in by Bart Vastenhouw, 2 years ago

Fixed small issues in domaineditor.

File size: 1.9 KB
Line 
1from decimal import Decimal
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5
6from geniusweb.issuevalue.DiscreteValue import DiscreteValue
7from geniusweb.profile.utilityspace.DiscreteValueSetUtilities import DiscreteValueSetUtilities
8from geniusweb.profile.utilityspace.ValueSetUtilities import ValueSetUtilities
9
10
11class DiscreteValSetUtilsTest(unittest.TestCase):
12 pyson=ObjectMapper()
13 N0=Decimal("0")
14 N1=Decimal("1")
15 N05=Decimal("0.5")
16 N07=Decimal("0.7")
17 high=DiscreteValue("high")
18 low=DiscreteValue("low")
19 medium=DiscreteValue("medium")
20
21 carreerutils = DiscreteValueSetUtilities({high:N1,low:N0,medium:N05})
22 carreerutils1 = DiscreteValueSetUtilities({high:N1,low:N0,medium:N05})
23 carreerutils2 = DiscreteValueSetUtilities({high:N1,low:N0,medium:N07})
24
25 carreerjson = {"DiscreteValueSetUtilities":{ "valueUtilities":{ "high":1, "medium":0.5, "low":0}}}
26 def testGetUtility(self):
27 self.assertEqual(self.N05, self.carreerutils.getUtility(self.medium))
28 self.assertEqual(self.N0, self.carreerutils.getUtility(DiscreteValue("nonexisting")))
29
30 def testSerialize(self):
31 print(self.pyson.toJson(self.carreerutils))
32 self.assertEqual(self.carreerjson, self.pyson.toJson(self.carreerutils))
33
34 def testDeserialize(self):
35 self.assertEqual(self.carreerutils, self.pyson.parse(self.carreerjson, ValueSetUtilities))
36
37
38 def testRepr(self):
39 self.assertEqual('DiscreteValueSetUtilities{"high"=1, "low"=0, "medium"=0.5}', repr(self.carreerutils))
40
41 def testEqual(self):
42 self.assertEqual(self.carreerutils, self.carreerutils1)
43 self.assertNotEqual(self.carreerutils, self.carreerutils2)
44 self.assertEqual(hash(self.carreerutils), hash(self.carreerutils1))
45 self.assertNotEqual(hash(self.carreerutils), hash(self.carreerutils2))
46
Note: See TracBrowser for help on using the repository browser.