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 |
|
---|
10 |
|
---|
11 | class ProgressRoundsTest(unittest.TestCase):
|
---|
12 | pyson=ObjectMapper()
|
---|
13 | progress = ProgressRounds(12, 0, datetime.fromtimestamp(100000.9))
|
---|
14 | progress1 = ProgressRounds(12, 0, datetime.fromtimestamp(100000.9))
|
---|
15 | progress2 = ProgressRounds(11, 0, datetime.fromtimestamp(100000.9))
|
---|
16 | progresjson = {"ProgressRounds":{"duration":12,"currentRound":0,"endtime":100000900}}
|
---|
17 | final=ProgressRounds(12,12, datetime.fromtimestamp(100000.9));
|
---|
18 |
|
---|
19 | def testDeserialization(self):
|
---|
20 | self.assertEqual(self.progress, self.pyson.parse(self.progresjson, Progress))
|
---|
21 |
|
---|
22 | def testSerialization(self):
|
---|
23 | print(self.pyson.toJson(self.progress))
|
---|
24 | self.assertEqual(self.progresjson, self.pyson.toJson(self.progress))
|
---|
25 |
|
---|
26 | def testRepr(self):
|
---|
27 | self.assertEqual("ProgressRounds[0 of 12,100000.9]", repr(self.progress))
|
---|
28 |
|
---|
29 | def testEqual(self):
|
---|
30 | self.assertEqual(self.progress, self.progress1)
|
---|
31 | self.assertNotEqual(self.progress, self.progress2)
|
---|
32 |
|
---|
33 | self.assertEqual(hash(self.progress), hash(self.progress1))
|
---|
34 | self.assertNotEqual(hash(self.progress), hash(self.progress2))
|
---|
35 |
|
---|
36 | def testDuration(self):
|
---|
37 | self.assertEqual(12, self.progress.getDuration())
|
---|
38 |
|
---|
39 | def testAdvance(self):
|
---|
40 | prog=self.progress.advance()
|
---|
41 | self.assertEqual(1, prog.getCurrentRound())
|
---|
42 |
|
---|
43 | def testAdvanceFinal(self):
|
---|
44 | self.final.advance()
|
---|
45 |
|
---|
46 | def testTerminationTime(self):
|
---|
47 | self.assertEqual(datetime.fromtimestamp(100000.9), self.progress.getTerminationTime())
|
---|
48 |
|
---|
49 | def testIsPastDeadline(self):
|
---|
50 | self.assertFalse(self.progress.isPastDeadline(500))
|
---|
51 | self.assertFalse(self.progress.isPastDeadline(100000900))
|
---|
52 | self.assertTrue(self.progress.isPastDeadline(100000901))
|
---|
53 |
|
---|
54 | self.assertTrue(self.final.isPastDeadline(100))
|
---|
55 |
|
---|
56 | def testGet(self):
|
---|
57 | self.assertEqual(0, self.progress.get(100000900-1))
|
---|
58 | # get ignores the time deadline.
|
---|
59 | self.assertEqual(0, self.progress.get(100000901))
|
---|
60 |
|
---|
61 | #check final if all rounds completed.
|
---|
62 | self.assertEqual(1, self.final.get(100000900-1))
|
---|
63 |
|
---|
64 | halfway = ProgressRounds(12,6, datetime.fromtimestamp(100000900));
|
---|
65 | self.assertEqual(0.5, halfway.get(100000900-1) )
|
---|