-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutil_test.py
55 lines (48 loc) · 1.55 KB
/
util_test.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import unittest
import util
import time
import random
from matplotlib import pyplot as plt
class Test_timer(unittest.TestCase):
def test_delay_timer(self):
delay_timer1 = util.DelayTimer(delay_time=0.5)
delay_timer2 = util.DelayTimer(delay_time=0.5, true_until=True)
vals1 = []
vals2 = []
for i in range(300):
time.sleep(0.01)
vals1.append(delay_timer1.check())
vals2.append(delay_timer2.check()+1.5)
if i == 50:
delay_timer1.start()
delay_timer2.start()
if i == 250:
delay_timer1.reset()
delay_timer2.reset()
plt.plot(vals1)
plt.plot(vals2)
plt.show()
# def test_single_time(self):
# custom_timer = util.FlexibleTimer(target_freq=2)
# t0 = time.time()
# custom_timer.pause()
# t1 = time.time()-t0
# print(t1)
# self.assertAlmostEqual(t1, 0.5, places=2)
# def test_timer(self):
# custom_timer = util.FlexibleTimer(target_freq=100)
# periods = []
# delays = []
# for _ in range(500):
# t0 = time.perf_counter()
# random_delay = 0.001*random.randint(1, 11)
# time.sleep(random_delay)
# delays.append(time.perf_counter()-t0)
# custom_timer.pause()
# periods.append(time.perf_counter()-t0)
# plt.Figure()
# plt.plot(delays)
# plt.plot(periods)
# plt.show()
if __name__ == '__main__':
unittest.main()