forked from keylime/keylime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_retry_algo.py
More file actions
40 lines (25 loc) · 900 Bytes
/
Copy pathtest_retry_algo.py
File metadata and controls
40 lines (25 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import random
import unittest
from keylime.common import retry
def rand_base():
return random.uniform(-99, 99)
def rand_base_proper():
return random.uniform(1, 99)
def rand_ntries():
return random.randint(1, 99)
def rand_exp():
return random.choice([True, False])
class RetryInterval_Test(unittest.TestCase):
def test_general(self):
self.assertTrue(retry.retry_time(rand_exp(), rand_base(), rand_ntries(), None) >= 0)
def test_linear(self):
b = rand_base()
self.assertEqual(retry.retry_time(False, b, rand_ntries(), None), abs(b))
def test_exponential(self):
b0 = rand_base_proper()
b1 = random.random()
n = rand_ntries()
self.assertEqual(retry.retry_time(True, b0, n, None), b0**n)
self.assertEqual(retry.retry_time(True, b1, n, None), abs(b1))
if __name__ == "__main__":
unittest.main()