source: geniuswebcore/test/geniusweb/issuevalue/DomainTest.py@ 62

Last change on this file since 62 was 59, checked in by Wouter Pasman, 3 years ago

#44 manual commit of first public release, because this will cause the dist directory to move

File size: 3.7 KB
Line 
1import json
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5
6from geniusweb.issuevalue.Bid import Bid
7from geniusweb.issuevalue.DiscreteValue import DiscreteValue
8from geniusweb.issuevalue.DiscreteValueSet import DiscreteValueSet
9from geniusweb.issuevalue.Domain import Domain
10from geniusweb.issuevalue.NumberValue import NumberValue
11
12
13class DomainTest (unittest.TestCase) :
14
15 pyson=ObjectMapper()
16
17 # test value as in java GeniusWeb
18 jobsstring = '{"name":"jobs",' \
19 + '"issuesValues":{' \
20 + '"lease car":{"values":["yes","no"]},' \
21 + '"permanent contract":{"values":["yes","no"]},' \
22 + '"career development opportunities":{"values":["low","medium","high"]},' \
23 + '"fte":{"values":["0.6","0.8","1.0"]},' \
24 + '"salary":{"values":["2000","2500","3000","3500","4000"]},' \
25 + '"work from home":{"values":["0","1","2"]}}}'
26 jobsjson = json.loads(jobsstring)
27 yesno = DiscreteValueSet([DiscreteValue("yes"), DiscreteValue("no")])
28 leasecarvals = yesno
29 permcontractvals = yesno
30 carreervals=DiscreteValueSet([DiscreteValue("low"),DiscreteValue("medium"),DiscreteValue("high")])
31 ftevals=DiscreteValueSet([DiscreteValue("0.6"),DiscreteValue("0.8"),DiscreteValue("1.0")])
32 salaryvals=DiscreteValueSet([DiscreteValue("2000"),DiscreteValue("2500"),DiscreteValue("3000"),DiscreteValue("3500"),DiscreteValue("4000")])
33 workfromhomevals=DiscreteValueSet([DiscreteValue("0"),DiscreteValue("1"),DiscreteValue("2")])
34
35 jobs = Domain("jobs", {"lease car":leasecarvals, "permanent contract":permcontractvals, \
36 "career development opportunities":carreervals, "fte":ftevals, \
37 "salary": salaryvals, "work from home": workfromhomevals })
38 jobs1 = Domain("jobs", {"lease car":leasecarvals, "permanent contract":permcontractvals, \
39 "career development opportunities":carreervals, "fte":ftevals, \
40 "salary": salaryvals, "work from home": workfromhomevals })
41
42 jobs2 = Domain("jobs2", {"lease car":leasecarvals, "permanent contract":permcontractvals, \
43 "career development opportunities":carreervals, "fte":ftevals, \
44 "salary": salaryvals, "work from home": workfromhomevals })
45
46 jobs3 = Domain("jobs", {"Lcar":leasecarvals, "permanent contract":permcontractvals, \
47 "career development opportunities":carreervals, "fte":ftevals, \
48 "salary": salaryvals, "work from home": workfromhomevals })
49
50 def testSerialize(self):
51 print(str(self.pyson.toJson(self.jobs)))
52 self.assertEqual(self.jobsjson,self.pyson.toJson(self.jobs))
53
54 def testDeserializeJobs(self):
55 self.assertEqual(self.jobs, self.pyson.parse(self.jobsjson, Domain))
56
57 def testIsFitting(self):
58 self.assertEqual(None,self.jobs.isFitting(Bid({"lease car":DiscreteValue("no")})))
59 self.assertTrue("illegal value maybe" in self.jobs.isFitting(Bid({"lease car":DiscreteValue("maybe")})))
60
61 def testRepr(self):
62 self.assertEqual("Domain[jobs,{'lease car': DiscreteValueSet[yes, no], 'permanent contract': DiscreteValueSet[yes, no], 'career development opportunities': DiscreteValueSet[low, medium, high], 'fte': DiscreteValueSet[0.6, 0.8, 1.0], 'salary': DiscreteValueSet[2000, 2500, 3000, 3500, 4000], 'work from home': DiscreteValueSet[0, 1, 2]}]", \
63 repr(self.jobs))
64
65 def testEqual(self):
66 self.assertEqual(self.jobs, self.jobs1)
67 self.assertNotEqual(self.jobs, self.jobs2)
68 self.assertNotEqual(self.jobs, self.jobs3)
69 self.assertNotEqual(self.jobs2, self.jobs3)
70 self.assertEqual(hash(self.jobs), hash(self.jobs1))
71 self.assertNotEqual(hash(self.jobs), hash(self.jobs2))
72
Note: See TracBrowser for help on using the repository browser.