1 |
|
---|
2 | from datetime import datetime
|
---|
3 | import unittest
|
---|
4 |
|
---|
5 | from pyson.ObjectMapper import ObjectMapper
|
---|
6 |
|
---|
7 | from geniusweb.progress.Progress import Progress
|
---|
8 | from geniusweb.progress.ProgressRounds import ProgressRounds
|
---|
9 | from geniusweb.progress.ProgressTime import ProgressTime
|
---|
10 |
|
---|
11 |
|
---|
12 | class ProgressTimeTest(unittest.TestCase):
|
---|
13 | pyson=ObjectMapper()
|
---|
14 | progress = ProgressTime(1999, datetime.fromtimestamp(100000.9))
|
---|
15 | progress1 = ProgressTime(1999, datetime.fromtimestamp(100000.9))
|
---|
16 | progress2 = ProgressTime(999, datetime.fromtimestamp(100000.9))
|
---|
17 | progress3 = ProgressTime(1999, datetime.fromtimestamp(100001.9))
|
---|
18 | progresjson = {"ProgressTime":{"duration":1999, 'start':100000900}}
|
---|
19 |
|
---|
20 | def testDeserialization(self):
|
---|
21 | self.assertEqual(self.progress, self.pyson.parse(self.progresjson, Progress))
|
---|
22 |
|
---|
23 | def testSerialization(self):
|
---|
24 | print(self.pyson.toJson(self.progress))
|
---|
25 | self.assertEqual(self.progresjson, self.pyson.toJson(self.progress))
|
---|
26 |
|
---|
27 | def testRepr(self):
|
---|
28 | self.assertEqual("ProgressTime[100000.9 , 1999ms]", repr(self.progress))
|
---|
29 |
|
---|
30 | def testEqual(self):
|
---|
31 | self.assertEqual(self.progress, self.progress1)
|
---|
32 | self.assertNotEqual(self.progress, self.progress2)
|
---|
33 | self.assertNotEqual(self.progress, self.progress3)
|
---|
34 | self.assertEqual(hash(self.progress), hash(self.progress1))
|
---|
35 | self.assertNotEqual(hash(self.progress), hash(self.progress2))
|
---|
36 | self.assertNotEqual(hash(self.progress), hash(self.progress3))
|
---|
37 |
|
---|
38 | def testPastDeadline(self):
|
---|
39 | self.assertFalse(self.progress.isPastDeadline(100000900+1999))
|
---|
40 | self.assertTrue(self.progress.isPastDeadline(100000900+1999+1))
|
---|
41 |
|
---|
42 | def testTerminationTime(self):
|
---|
43 | self.assertEqual(datetime.fromtimestamp((100000900+1999)/1000), self.progress.getTerminationTime())
|
---|
44 |
|
---|
45 | def testGet(self):
|
---|
46 | self.assertEqual(0, self.progress.get(100000.9))
|
---|
47 | self.assertEqual(1, self.progress.get(100000.9+1999))
|
---|
48 | self.assertEqual(0.5, self.progress.get(100000.9+1999/2)) |
---|