source: geniuswebcore/test/geniusweb/inform/AgreementsTest.py@ 88

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

Added python SimpleRunner GUI

File size: 2.0 KB
Line 
1import unittest
2
3from pyson.ObjectMapper import ObjectMapper
4
5from geniusweb.actions.PartyId import PartyId
6from geniusweb.inform.Agreements import Agreements
7from geniusweb.inform.Inform import Inform
8from geniusweb.issuevalue.Bid import Bid
9from geniusweb.issuevalue.DiscreteValue import DiscreteValue
10
11
12class AgreementsTest(unittest.TestCase):
13 pyson=ObjectMapper()
14 id1 = PartyId("party1")
15 id2 = PartyId("party2")
16 bid1 = Bid({"issue1":DiscreteValue("value1")})
17 bid2 = Bid({"issue2":DiscreteValue("value1")})
18
19 agrees = Agreements({id1: bid1 })
20 agrees1 = Agreements({id1: bid1 })
21 agrees2 = Agreements({ id2: bid1 })
22 agrees3 = Agreements({ id1: bid2 })
23
24 agrees1json:dict={"party1":{"issuevalues":{"issue1":"value1"}}}
25
26 def testNull(self) :
27 Agreements();
28
29 def testNone(self) :
30 self.assertRaises(ValueError, lambda:Agreements(None))
31
32 def testWithAlreadyActed(self) :
33 self.assertRaises(ValueError, lambda:self.agrees1.With(self.agrees1))
34
35 def testWith(self):
36 agrees = self.agrees1.With(self.agrees2);
37 self.assertEquals(self.bid1, agrees.getMap()[self.id1]);
38 self.assertEquals(self.bid1, agrees.getMap()[self.id2]);
39
40 def testSerialize(self):
41 print(str(self.pyson.toJson(self.agrees1)))
42 self.assertEqual(self.agrees1json, self.pyson.toJson(self.agrees1))
43
44 def testDeserialize(self):
45 self.assertEqual(self.agrees1, self.pyson.parse(self.agrees1json, Agreements))
46
47 def testRepr(self):
48 self.assertEqual('Agreements{party1=Bid{issue1="value1"}}', repr(self.agrees))
49
50 def testEqual(self):
51 self.assertEqual(self.agrees, self.agrees1)
52 self.assertNotEqual(self.agrees, self.agrees2)
53 self.assertNotEqual(self.agrees, self.agrees3)
54 self.assertEqual(hash(self.agrees), hash(self.agrees1))
55 self.assertNotEqual(hash(self.agrees), hash(self.agrees2))
56 self.assertNotEqual(hash(self.agrees), hash(self.agrees3))
57
58
Note: See TracBrowser for help on using the repository browser.