-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.py
33 lines (30 loc) · 3.5 KB
/
utils.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
from unittest import TestCase
class Test_PA(TestCase):
def test(self, find_peaks):
self.assertEqual(find_peaks([1,2,3,6,4,1,2,3,2,1]), {"pos": [3,7], "peaks": [6,3]})
self.assertEqual(find_peaks([3,2,3,6,4,1,2,3,2,1,2,3]), {"pos": [3,7], "peaks": [6,3]})
self.assertEqual(find_peaks([3,2,3,6,4,1,2,3,2,1,2,2,2,1]), {"pos": [3,7,10], "peaks": [6,3,2]})
self.assertEqual(find_peaks([2,1,3,1,2,2,2,2,1]), {"pos": [2,4], "peaks": [3,2]})
self.assertEqual(find_peaks([2,1,3,1,2,2,2,2]), {"pos": [2], "peaks": [3]})
self.assertEqual(find_peaks([2,1,3,2,2,2,2,5,6]), {"pos": [2], "peaks": [3]})
self.assertEqual(find_peaks([2,1,3,2,2,2,2,1]), {"pos": [2], "peaks": [3]})
self.assertEqual(find_peaks([1,2,5,4,3,2,3,6,4,1,2,3,3,4,5,3,2,1,2,3,5,5,4,3]), {"pos": [2,7,14,20], "peaks": [5,6,5,5]})
self.assertEqual(find_peaks([-3,10,9,18,8,-4,-5,4,12,1,15,-5,10,2,18,3,5,12,12]), {"pos": [1,3,8,10,12,14], "peaks": [10,18,12,15,10,18]})
self.assertEqual(find_peaks([15,19,18,-2,3,6,19,20,-4,19,-5,-5,-3,8,18,15,-4,-1,14]), {"pos": [1,7,9,14], "peaks": [19, 20, 19, 18]})
self.assertEqual(find_peaks([]), {"pos": [], "peaks": []})
self.assertEqual(find_peaks([1,1,1,1]), {"pos": [], "peaks": []})
print("Test OK")
class Test_PB(TestCase):
def test(self, max_list):
self.assertEqual(max_list([-2, 1, -3, 4, -1, 2, 1, -5, 4]), 6)
self.assertEqual(max_list([-2, -1, -3, -4, -1, -2, -1, -5, -4]), 0)
self.assertEqual(max_list([11, 5, 22, -12, -22, -12, 23, 26, 29, 22, -2, 9, 13, 2, -17, 6, 12, -27, 14, -5, -27, 10, -22, -5, 9, 1, -4, 8, 18, 30, 9, -23, -24, -10, -25, 28, 0, -1, 5, -16, -29, 30, -20, -10, -5, -17, 17, -4, 24, 11]), 132)
self.assertEqual(max_list([16, 25, -15, -21, -21, -26, -1, 19, -13, 1, -3, -29, 23, -14, -26, 5, -8, -4, 3, 10, -13, -20, -25, -23, 25, 25, -3, -27, 1, -26, -9, -20, -13, -25, 2, 18, 1, -21, -23, 7, -2, 28, -15, 25, -6, -13, 17, -27, -2, 15]), 50)
self.assertEqual(max_list([12, 20, -19, -28, 30, 13, 24, 0, 10, 29, 9, -14, -8, -6, 7, -8, 30, 10, -8, -22, -5, 23, -20, -7, 4, 16, 20, 15, -8, 6, 9, 24, 14, -4, -6, 22, -21, 15, 29, -30, -3, 22, 10, -18, 19, 11, -21, 21, 3, -5] ), 236)
self.assertEqual(max_list([4, -13, -21, -6, 21, -20, 18, 29, 10, 23, 21, -22, -24, -8, 0, 29, -9, 15, -8, -18, -7, 14, 11, -27, 26, 29, 5, -10, -13, -23, 27, 0, -30, -20, -6, -10, -13, -18, -11, 28, -7, -30, -25, -20, 5, -29, 28, -6, 19, 29]), 108)
self.assertEqual(max_list([17, -8, 29, 24, -26, -7, 19, 28, -23, 2, 18, -2, 19, -20, 29, 17, -18, -17, -8, -6, 17, 28, 30, 9, 25, -22, -30, -14, -6, 6, -15, -14, -12, 17, -11, -26, 21, -18, 30, 17, -14, 6, 28, -9, -8, 11, -26, 14, -26, 17]), 176)
self.assertEqual(max_list([-29, 30, 1, -24, -7, -30, 30, 9, 11, 23, 4, 18, -10, -21, 25, -12, 2, -5, 7, 23, 1, -29, 27, 9, 29, 23, -19, -11, 4, 29, -23, 1, 5, 9, 3, 17, 3, -26, 15, 26, -13, -4, -7, 5, 22, -26, -10, 1, 7, 9]), 200)
self.assertEqual(max_list([-1, -3, 6, 24, 27, -9, 8, 26, -14, 11, -9, 3, -5, 27, 9, -19, -1, 11, -21, -7, -5, -6, -3, 18, -2, 0, 25, 4, -2, 28, 17, -22, 9, -2, -6, -3, -9, -29, -11, 4, 27, 13, 7, -24, 15, 22, -10, 7, -19, -21] ), 141)
self.assertEqual(max_list([9, -24, -10, 18, 11, -11, 29, 28, -21, -5, -5, -26, 7, 5, -17, -22, -21, -20, -26, -5, 5, -9, 24, 18, -8, 11, -18, 9, 13, 1, -5, -27, -7, -15, -4, 9, 21, 7, 25, -14, -19, 27, -8, -10, 28, 2, -8, -5, 18, -27]), 75)
self.assertEqual(max_list([]), 0)
print("Test OK")