source: geniuswebcore/test/geniusweb/profile/utilityspace/NumberValSetUtilsTest.py@ 88

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

Added python SimpleRunner GUI

File size: 2.5 KB
Line 
1from decimal import Decimal
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5
6from geniusweb.issuevalue.DiscreteValue import DiscreteValue
7from geniusweb.issuevalue.NumberValue import NumberValue
8from geniusweb.profile.utilityspace.DiscreteValueSetUtilities import DiscreteValueSetUtilities
9from geniusweb.profile.utilityspace.NumberValueSetUtilities import NumberValueSetUtilities
10from geniusweb.profile.utilityspace.ValueSetUtilities import ValueSetUtilities
11
12
13class NumberValSetUtilsTest(unittest.TestCase):
14 pyson=ObjectMapper()
15 N0=Decimal("0")
16 N04=Decimal("0.4")
17 N05=Decimal("0.5")
18 N065=Decimal("0.65")
19 N09=Decimal("0.9")
20 N1=Decimal("1")
21
22 salaryutils = NumberValueSetUtilities(Decimal(1000),N04, Decimal(3000),N09)
23 salaryutils1 = NumberValueSetUtilities(Decimal(1000),N04, Decimal("3000"),N09)
24 salaryutils2 = NumberValueSetUtilities(Decimal(1100),N04, Decimal("3000"),N09)
25 salaryutils3 = NumberValueSetUtilities(Decimal(1000),N05, Decimal("3000"),N09)
26 salaryjson:dict={"NumberValueSetUtilities":{ 'highUtility': 0.9, 'highValue': 3000,
27 'lowUtility': 0.4, 'lowValue': 1000}}
28
29 def testGetUtility(self):
30 self.assertEqual(self.N04, self.salaryutils.getUtility(NumberValue(Decimal(1000))))
31 self.assertEqual(self.N065, self.salaryutils.getUtility(NumberValue(Decimal(2000))))
32 self.assertEqual(self.N09, self.salaryutils.getUtility(NumberValue(Decimal(3000))))
33 self.assertEqual(self.N0, self.salaryutils.getUtility(Decimal(12)))
34
35
36 def testSerialize(self):
37 print(self.pyson.toJson(self.salaryutils))
38 self.assertEqual(self.salaryjson, self.pyson.toJson(self.salaryutils))
39
40 def testDeserialize(self):
41 self.assertEqual(self.salaryutils, self.pyson.parse(self.salaryjson, ValueSetUtilities))
42
43 def testRepr(self):
44 self.assertEqual("NumberValueSetUtilities[1000->0.4,3000->0.9]", repr(self.salaryutils))
45
46 def testEqual(self):
47 self.assertEqual(self.salaryutils, self.salaryutils1)
48 self.assertNotEqual(self.salaryutils, self.salaryutils2)
49 self.assertNotEqual(self.salaryutils, self.salaryutils3)
50 self.assertEqual(hash(self.salaryutils), hash(self.salaryutils1))
51 self.assertNotEqual(hash(self.salaryutils), hash(self.salaryutils2))
52 self.assertNotEqual(hash(self.salaryutils), hash(self.salaryutils3))
53
Note: See TracBrowser for help on using the repository browser.