source: geniuswebcore/test/geniusweb/actions/VotesTest.py@ 73

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

Fix for IssueValue hashcode.

File size: 4.2 KB
Line 
1import json
2import unittest
3
4from pyson.ObjectMapper import ObjectMapper
5
6from geniusweb.actions.Action import Action
7from geniusweb.actions.PartyId import PartyId
8from geniusweb.actions.Vote import Vote
9from geniusweb.actions.Votes import Votes
10from geniusweb.issuevalue.Bid import Bid
11from geniusweb.issuevalue.DiscreteValue import DiscreteValue
12
13
14class VotesTest (unittest.TestCase) :
15 maxDiff = None
16
17 jackson = ObjectMapper();
18 votestring = "{\"Votes\":{\"actor\":\"partyA\",\"votes\":[{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val1\"}},\"minPower\":2,\"maxPower\":9}},{\"Vote\":{\"actor\":\"partyA\",\"bid\":{\"issuevalues\":{\"is1\":\"val2\"}},\"minPower\":2,\"maxPower\":9}}]}}";
19
20 partyA = PartyId("partyA");
21 partyB = PartyId("partyB");
22 bid1 = Bid({"is1": DiscreteValue("val1")})
23 bid2 = Bid({"is1": DiscreteValue("val2")})
24 voteA1 = Vote(partyA, bid1, 2, 9)
25 voteA2 = Vote(partyA, bid2, 2, 9)
26 voteB1 = Vote(partyB, bid1, 2, 9)
27 voteB2 = Vote(partyB, bid2, 2, 9)
28
29 votes1 = Votes(partyA,set([voteA1, voteA2]))
30 votes1a=Votes(partyA,set([voteA1, voteA2]))
31 votes2 = Votes(partyB,set([voteB1, voteB2]))
32
33 def testRejectVoteWithIncorrectParty(self):
34 self.assertRaises(ValueError, lambda: Votes(self.partyA, set([self.voteB1])) )
35
36
37 def tes1Serialize(self) :
38 # FIXME why is this failing half of the time?
39 print(str(self.jackson.toJson(self.votes1)));
40 self.assertEqual(json.loads(self.votestring), self.jackson.toJson(self.votes1))
41
42 def testDeserialize(self) :
43 act = self.jackson.parse(json.loads(self.votestring), Action)
44 self.assertEqual(self.votes1, act)
45
46 def testWrongPartyName(self):
47 self.assertRaises(ValueError, lambda:\
48 Votes(self.partyA, set([self.voteB1, self.voteB2])))
49
50 def testIsExtendingTestExtraVote(self):
51 otherVotes = Votes(self.partyA, set([self.voteA1]))
52 self.assertTrue(self.votes1.isExtending(otherVotes))
53
54 def testIsExtendingTestNoVotes(self) :
55 otherVotes = Votes(self.partyA, set())
56 self.assertTrue(self.votes1.isExtending(otherVotes))
57
58 def testIsExtendingTestMissing(self):
59 otherVotes = Votes(self.partyA, set([self.voteA1]))
60 self.assertFalse(otherVotes.isExtending(self.votes1))
61
62 def testIsExtendingIdenticalVotes(self):
63 self.assertTrue(self.votes1.isExtending(self.votes1))
64
65# @Test
66# public void isReallyExtendingVotesMin() {
67# Vote powervoteA1 = new Vote(partyA, bid1, 1, 9);
68# Votes powerVotes = new Votes(partyA,
69# new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
70# assertTrue(powerVotes.isExtending(votes1));
71# }
72#
73# @Test
74# public void isReallyExtendingVotesMax() {
75# Vote powervoteA1 = new Vote(partyA, bid1, 2, 10);
76# Votes powerVotes = new Votes(partyA,
77# new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
78# assertTrue(powerVotes.isExtending(votes1));
79# }
80#
81# @Test
82# public void IsNarrowingOneVoteRemoved() {
83# Votes narrowVotes = new Votes(partyA, Collections.singleton(voteA2));
84# assertFalse(narrowVotes.isExtending(votes1));
85# }
86#
87# @Test
88# public void isNarrowingTestMoreMinPower() {
89# Vote narrowVoteA1 = new Vote(partyA, bid1, 3, 9);
90# Votes narrowVotes = new Votes(partyA,
91# new HashSet<>(Arrays.asList(narrowVoteA1, voteA2)));
92# assertFalse(narrowVotes.isExtending(votes1));
93# assertTrue(votes1.isExtending(narrowVotes));
94# }
95#
96# @Test
97# public void isNarrowingLessMaxPower() {
98# Vote powervoteA1 = new Vote(partyA, bid1, 2, 8);
99# Votes narrowVotes = new Votes(partyA,
100# new HashSet<>(Arrays.asList(powervoteA1, voteA2)));
101# assertFalse(narrowVotes.isExtending(votes1));
102# assertTrue(votes1.isExtending(narrowVotes));
103# }
104#
105# @Test(expected = IllegalArgumentException.class)
106# public void testDuplicateBidsNotAllowed() {
107# Vote voteA1similar = new Vote(partyA, bid1, 3, 9);
108# Votes votes = new Votes(partyA,
109# new HashSet<>(Arrays.asList(voteA1, voteA1similar)));
110# }
111# }
Note: See TracBrowser for help on using the repository browser.