[81] | 1 | import unittest
|
---|
| 2 | from pyson.ObjectMapper import ObjectMapper
|
---|
| 3 | from decimal import Decimal
|
---|
| 4 | from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive
|
---|
| 5 | import json
|
---|
| 6 | from pathlib import Path
|
---|
| 7 | from geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace import LinearAdditiveUtilitySpace
|
---|
| 8 | from timedependentparty.ExtendedUtilSpace import ExtendedUtilSpace
|
---|
| 9 |
|
---|
| 10 | class ExtendedUtilSpaceTest(unittest.TestCase):
|
---|
| 11 | jackson = ObjectMapper()
|
---|
| 12 | SMALL = Decimal("0.0001")
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | parameters=[
|
---|
| 16 | ["test/resources/jobs/jobs1.json", Decimal(0.02) ],
|
---|
| 17 | [ "test/resources/7issues/7issues1.json", Decimal(0.0055) ],
|
---|
| 18 | ["test/resources/9issues/9issues1.json", Decimal(0.0013) ]
|
---|
| 19 | ]
|
---|
| 20 |
|
---|
| 21 | def testAll(self):
|
---|
| 22 | '''
|
---|
| 23 | runs all the tests. Python has no standard 'parameterized' mechanism
|
---|
| 24 | so we have to do it ourselves.
|
---|
| 25 | '''
|
---|
| 26 | for [filename, expectedtolerance] in self.parameters:
|
---|
| 27 | self.filename=filename
|
---|
| 28 | self.expectedTolerance= expectedtolerance
|
---|
| 29 | with self.subTest("testsmokeTest"+self.filename):
|
---|
| 30 | self.before()
|
---|
| 31 | self.smoke()
|
---|
| 32 | with self.subTest("testTolerance"+self.filename):
|
---|
| 33 | self.before()
|
---|
| 34 | self.Tolerance()
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | def before(self) :
|
---|
| 39 | file = Path(self.filename).read_text("utf-8")
|
---|
| 40 | profile=self.jackson.parse(json.loads(file), LinearAdditiveUtilitySpace)
|
---|
| 41 | self.space=ExtendedUtilSpace(profile)
|
---|
| 42 | print("self.space="+str(self.space))
|
---|
| 43 |
|
---|
| 44 | def smoke(self):
|
---|
| 45 | pass
|
---|
| 46 |
|
---|
| 47 | def Tolerance(self):
|
---|
| 48 | self.assertTrue(abs(self.space._computeTolerance()-self.expectedTolerance) < self.SMALL)
|
---|