1 | import json
|
---|
2 | import unittest
|
---|
3 |
|
---|
4 | from pyson.ObjectMapper import ObjectMapper
|
---|
5 |
|
---|
6 | from geniusweb.actions.Offer import Offer
|
---|
7 | from geniusweb.actions.PartyId import PartyId
|
---|
8 | from geniusweb.inform.Inform import Inform
|
---|
9 | from geniusweb.inform.Voting import Voting
|
---|
10 | from geniusweb.issuevalue.Bid import Bid
|
---|
11 | from geniusweb.issuevalue.DiscreteValue import DiscreteValue
|
---|
12 | from typing import List
|
---|
13 | from unitpy.GeneralTests import GeneralTests
|
---|
14 |
|
---|
15 |
|
---|
16 | class 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 | |
---|