-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
120 lines (102 loc) · 3.87 KB
/
tests.py
File metadata and controls
120 lines (102 loc) · 3.87 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import pytest
from utils import Solution
data = [
([[1, 5, 9], [10, 11, 13], [12, 13, 15]], 8, 13),
([[-5]], 1, -5),
([[1, 2], [1, 3]], 1, 1),
([[1, 4], [2, 5]], 2, 2),
]
@pytest.mark.parametrize("param, k , expected", data)
def test_kthSmallest(param, k, expected):
s = Solution()
assert s.kthSmallest(param, k) == expected
@pytest.mark.parametrize(
"st, expected",
[
("babad", ["bab", "aba"]),
("cbbd", ("bb")),
("a", ("a")),
("ac", ["a", "c"]),
("bb", ["bb"]),
("babadbab", ("bab", "aba")),
("abbcccbbbcaaccbababcbcabca", ("bbcccbb", "cbababc")),
("babaddtattarrattatddetartrateedredividerb", ("ddtattarrattatdd")),
(
"daomdukomcayjwgmmetypncdeixarhbectjcwftjjtwjrctixtrsehegwlfotpljeeqhntacfihecdjysgfmxxbjfeskvvfqdoedfxriujnoeteleftsjgdsagqvcgcdjbxgmguunhbjxyajutohgbdwqtjghdftpvidkbftqbpeahxbfyamonazvubzirhqseetaneptnpjbtrtitttxsyjckjvwtrmuwgidkofvobrwrffzrpnxbectsydbvswstfiqranjzhsebjnmprjoirqkgttahrivkcjtitdcpohwwerwgrdivqbltfnigavydxpmitttjjzyrmpaptkczzgnsovebvxezkkovgqegctxacvjfqwtiycnhartzczcgosiquhmdbljjzyrnmffcwnkyzytnsvyzayrieqyrfpxintbbiyrawxlguzaisedwabpzvevlejadztuclcpwvonehkhknicdksdcnjfaoeaqhcdkdtywilwewadcnaprcasccdcnvdgjdqirrsqwzhqqorlhbgpelpupdvuynzybcqkffnnpocidkkigimsa",
(
"daomdukomcayjwgmmetypncdeixarhbectjcwftjjtwjrctixtrsehegwlfotpljeeqhntacfihecdjysgfmxxbjfeskvvfqdoedfxriujnoeteleftsjgdsagqvcgcdjbxgmguunhbjxyajutohgbdwqtjghdftpvidkbftqbpeahxbfyamonazvubzirhqseetaneptnpjbtrtitttxsyjckjvwtrmuwgidkofvobrwrffzrpnxbectsydbvswstfiqranjzhsebjnmprjoirqkgttahrivkcjtitdcpohwwerwgrdivqbltfnigavydxpmitttjjzyrmpaptkczzgnsovebvxezkkovgqegctxacvjfqwtiycnhartzczcgosiquhmdbljjzyrnmffcwnkyzytnsvyzayrieqyrfpxintbbiyrawxlguzaisedwabpzvevlejadztuclcpwvonehkhknicdksdcnjfaoeaqhcdkdtywilwewadcnaprcasccdcnvdgjdqirrsqwzhqqorlhbgpelpupdvuynzybcqkffnnpocidkkigimsa"
),
),
],
)
def test_longestPalindrome(st, expected):
s = Solution()
assert s.longestPalindrome(st) in expected
# @pytest.mark.parametrize('nums1, nums2, expected', [
# ([1, 2, 3, 3, 2, 1], [1, 2, 1, 3, 2, 1], 3),
# ])
# def test_findLength(nums1, nums2, expected):
# s = Solution()
# assert s.findLength(nums1, nums2) == expected
@pytest.mark.parametrize(
"nums, expected",
[
([1, 2, 3, 4], 24),
([1], 1),
([], 0),
([1, 2, 3], 6),
([1, 2, 3, 4, 5, 6, 7], 7 * 6 * 5 * 4 * 3 * 2),
],
)
def test_permute(nums, expected):
s = Solution()
assert len(s.permute(nums)) == expected
@pytest.mark.parametrize(
"s, nrows, expected",
[
("01234567890", 4, "06157248039"),
("a", 1, "a"),
("", 2, ""),
("PAYPALISHIRING", 3, "PAHNAPLSIIGYIR"),
("PAYPALISHIRING", 4, "PINALSIGYAHRPI"),
],
)
def test_convert(s, nrows, expected):
sol = Solution()
assert sol.convert(s, nrows) == expected
@pytest.mark.parametrize(
"nums, expected",
[
([1, 2, 1, 3], (1, 3)),
([1], (0,)),
([1, 0, 1, 3, 4, 3], (0, 4)),
([1, 2], (1,)),
([2, 1], (0,)),
([6, 1, 3, 1, 2], (0, 2, 4)),
([1, 2, 1, 3, 5, 6, 4], (1, 5)),
([3, 2, 1, 0, -1, 0, 1], (0,)),
],
)
def test_peakElement(nums, expected):
sol = Solution()
assert sol.findPeakElement(nums) in expected
@pytest.mark.parametrize(
"order, s, expected",
[
("cba", "abcd", "dcba"),
("321", "1234", "4321"),
],
)
def test_customSort(order: str, s: str, expected: str):
sol = Solution()
assert sol.customSortString(order, s) == expected
@pytest.mark.parametrize(
"nums, target, expected",
[
("cba", "abcd", "dcba"),
("321", "1234", "4321"),
],
)
def test_findTargetSumWays(nums: str, target: str, expected: str):
sol = Solution()
assert sol.findTargetSumWays(nums, target) == expected