source: geniuswebcore/test/geniusweb/inform/VotingTest.py@ 82

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

Added python timedependent parties (conceder, hardliner, etc)

File size: 2.0 KB
Line 
1import json
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5
6from geniusweb.actions.Offer import Offer
7from geniusweb.actions.PartyId import PartyId
8from geniusweb.inform.Inform import Inform
9from geniusweb.inform.Voting import Voting
10from geniusweb.issuevalue.Bid import Bid
11from geniusweb.issuevalue.DiscreteValue import DiscreteValue
12from typing import List
13from unitpy.GeneralTests import GeneralTests
14
15
16class VotingTest(unittest.TestCase,GeneralTests[Voting]):
17 maxDiff = None
18
19 jackson = ObjectMapper();
20 party1 = PartyId("party1");
21 bid1 = Bid({"iss": DiscreteValue("val1")})
22 bid2 = Bid({"iss": DiscreteValue("val2")})
23
24 powers1 = {party1: 2}
25 powers2 = {party1: 3}
26
27 voting1 = Voting([Offer(party1, bid1)], powers1)
28 voting1a = Voting([Offer(party1, bid1)], powers1)
29 voting2 = Voting([ Offer(party1, bid2)], powers1)
30 voting3 = Voting([ Offer(party1, bid1)], powers2);
31
32 asJson="{\"Voting\":{\"offers\":[{\"Offer\":{\"actor\":\"party1\",\"bid\":{\"issuevalues\":{\"iss\":\"val1\"}}}}],\"powers\":{\"party1\":2}}}"
33
34 def getGeneralTestData(self)-> List[List[Voting]]:
35 return [[self.voting1, self.voting1a], [self.voting2], [self.voting3]]
36
37
38 def getGeneralTestStrings(self)-> List[str]:
39 return ["Voting.*Bid.*iss.*val1.*party1.*2.*",
40 "Voting.*Bid.*iss.*val2.*party1.*2.*",
41 "Voting.*Bid.*iss.*val1.*party1.*3.*"]
42
43
44
45 def testGeneralTestData(self):
46 self.assertEqual(self.voting1, self.voting1a)
47 self.assertEqual(hash(self.voting1), hash(self.voting1a))
48 self.assertNotEqual(self.voting1, self.voting2)
49 self.assertNotEqual(hash(self.voting1), hash(self.voting2))
50
51
52 def testSerialize(self) :
53 jsondict = self.jackson.toJson(self.voting1);
54 print(jsondict);
55 self.assertEqual(json.loads(self.asJson), jsondict);
56
57 def testDeserialize(self):
58 p = self.jackson.parse(json.loads(self.asJson), Inform)
59 print(p)
60 self.assertEqual(self.voting1, p)
61
Note: See TracBrowser for help on using the repository browser.