source: exampleparties/timedependentparty/test/ExtendedUtilSpaceTest.py@ 88

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

Added python SimpleRunner GUI

File size: 1.4 KB
Line 
1import unittest
2from pyson.ObjectMapper import ObjectMapper
3from decimal import Decimal
4from geniusweb.profile.utilityspace.LinearAdditive import LinearAdditive
5import json
6from pathlib import Path
7from geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace import LinearAdditiveUtilitySpace
8from timedependentparty.ExtendedUtilSpace import ExtendedUtilSpace
9
10class 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)
Note: See TracBrowser for help on using the repository browser.