-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
executable file
·92 lines (58 loc) · 2.42 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python
# Some tests for pingexp.
import unittest
import pingexp
class TestLostSequenceNumbers(unittest.TestCase):
def setUp(self):
pass
def test_1(self):
"""Test no lost packets."""
results = {'responses': [(1, 64, 0), (2, 64, 0), (3, 64, 0), (4, 64, 0)],
'summary': {'transmitted': 4, 'received': 4},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [])
def test_2(self):
"""Test first packet being lost."""
results = {'responses': [(2, 64, 0), (3, 64, 0)],
'summary': {'transmitted': 3, 'received': 2},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [1])
def test_3(self):
"""Test first three packets being lost."""
results = {'responses': [(4, 64, 0), (5, 64, 0), (6, 64, 0)],
'summary': {'transmitted': 6, 'received': 3},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [1,2,3])
def test_4(self):
"""Test single lost packet."""
results = {'responses': [(1, 64, 0), (2, 64, 0), (4, 64, 0)],
'summary': {'transmitted': 4, 'received': 3},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [3])
def test_5(self):
"""Test single lost packet at the end."""
results = {'responses': [(1, 64, 0), (2, 64, 0), (3, 64, 0)],
'summary': {'transmitted': 4, 'received': 3},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [4])
def test_6(self):
"""Test 3 lost packets at the end."""
results = {'responses': [(1, 64, 0), (2, 64, 0), (3, 64, 0)],
'summary': {'transmitted': 6, 'received': 3},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [4,5,6])
def test_7(self):
"""Combined test."""
results = {'responses': [(2, 64, 0), (3, 64, 0), (5, 64, 0), (6, 64, 0), (8,64,0), (9,64,0)],
'summary': {'transmitted': 12, 'received': 6},
}
r = pingexp.find_lost_sequence_numbers(results)
self.assertTrue(r == [1,4,7,10,11,12])
if __name__ == '__main__':
unittest.main()