Skip to content

Commit 64165e2

Browse files
committed
test: test more solutions
1 parent 5c69d0c commit 64165e2

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

leetcode/binary_tree_right_side_view/test_solution.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from leetcode_py.test_utils import logged_test
44

55
from .helpers import assert_right_side_view, run_right_side_view
6-
from .solution import Solution
6+
from .solution import Solution, SolutionBFS, SolutionDFS
77

88

99
class TestBinaryTreeRightSideView:
1010
def setup_method(self):
1111
self.solution = Solution()
1212

1313
@logged_test
14+
@pytest.mark.parametrize("solution_class", [Solution, SolutionDFS, SolutionBFS])
1415
@pytest.mark.parametrize(
1516
"root_list, expected",
1617
[
@@ -30,6 +31,8 @@ def setup_method(self):
3031
([10, 5, 15, None, 6, 12, 20], [10, 15, 20]),
3132
],
3233
)
33-
def test_right_side_view(self, root_list: list[int | None], expected: list[int]):
34-
result = run_right_side_view(Solution, root_list)
34+
def test_right_side_view(
35+
self, solution_class: type, root_list: list[int | None], expected: list[int]
36+
):
37+
result = run_right_side_view(solution_class, root_list)
3538
assert_right_side_view(result, expected)

leetcode/invert_binary_tree/test_solution.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from leetcode_py.test_utils import logged_test
44

55
from .helpers import assert_invert_tree, run_invert_tree
6-
from .solution import Solution
6+
from .solution import Solution, SolutionBFS, SolutionDFS
77

88

99
class TestInvertBinaryTree:
1010
def setup_method(self):
1111
self.solution = Solution()
1212

1313
@logged_test
14+
@pytest.mark.parametrize("solution_class", [Solution, SolutionDFS, SolutionBFS])
1415
@pytest.mark.parametrize(
1516
"root_list, expected_list",
1617
[
@@ -31,6 +32,8 @@ def setup_method(self):
3132
([1, 2, 3, None, 4, None, 5], [1, 3, 2, 5, None, 4]),
3233
],
3334
)
34-
def test_invert_tree(self, root_list: list[int | None], expected_list: list[int | None]):
35-
result = run_invert_tree(Solution, root_list)
35+
def test_invert_tree(
36+
self, solution_class: type, root_list: list[int | None], expected_list: list[int | None]
37+
):
38+
result = run_invert_tree(solution_class, root_list)
3639
assert_invert_tree(result, expected_list)

leetcode/longest_palindromic_substring/test_solution.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from leetcode_py.test_utils import logged_test
44

55
from .helpers import assert_longest_palindrome, run_longest_palindrome
6-
from .solution import Solution
6+
from .solution import Solution, SolutionManacher
77

88

99
class TestLongestPalindromicSubstring:
1010
def setup_method(self):
1111
self.solution = Solution()
1212

1313
@logged_test
14+
@pytest.mark.parametrize("solution_class", [Solution, SolutionManacher])
1415
@pytest.mark.parametrize(
1516
"s, expected",
1617
[
@@ -28,6 +29,6 @@ def setup_method(self):
2829
("abcba", {"abcba"}),
2930
],
3031
)
31-
def test_longest_palindrome(self, s: str, expected: set[str]):
32-
result = run_longest_palindrome(Solution, s)
32+
def test_longest_palindrome(self, solution_class: type, s: str, expected: set[str]):
33+
result = run_longest_palindrome(solution_class, s)
3334
assert_longest_palindrome(result, expected)

leetcode/lru_cache/test_solution.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from leetcode_py.test_utils import logged_test
44

55
from .helpers import assert_lru_cache, run_lru_cache
6-
from .solution import LRUCache
6+
from .solution import LRUCache, LRUCacheWithDoublyList
77

88

99
class TestLRUCache:
1010

1111
@logged_test
12+
@pytest.mark.parametrize("solution_class", [LRUCache, LRUCacheWithDoublyList])
1213
@pytest.mark.parametrize(
1314
"operations, inputs, expected",
1415
[
@@ -66,6 +67,12 @@ class TestLRUCache:
6667
),
6768
],
6869
)
69-
def test_lru_cache(self, operations: list[str], inputs: list[list[int]], expected: list[int | None]):
70-
result, _ = run_lru_cache(LRUCache, operations, inputs)
70+
def test_lru_cache(
71+
self,
72+
solution_class: type,
73+
operations: list[str],
74+
inputs: list[list[int]],
75+
expected: list[int | None],
76+
):
77+
result, _ = run_lru_cache(solution_class, operations, inputs)
7178
assert_lru_cache(result, expected)

leetcode/partition_equal_subset_sum/test_solution.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from leetcode_py.test_utils import logged_test
44

55
from .helpers import assert_can_partition, run_can_partition
6-
from .solution import Solution
6+
from .solution import Solution, SolutionBitset
77

88

99
class TestPartitionEqualSubsetSum:
1010
def setup_method(self):
1111
self.solution = Solution()
1212

1313
@logged_test
14+
@pytest.mark.parametrize("solution_class", [Solution, SolutionBitset])
1415
@pytest.mark.parametrize(
1516
"nums, expected",
1617
[
@@ -31,6 +32,6 @@ def setup_method(self):
3132
([4, 4, 4, 4, 4, 4], True),
3233
],
3334
)
34-
def test_can_partition(self, nums: list[int], expected: bool):
35-
result = run_can_partition(Solution, nums)
35+
def test_can_partition(self, solution_class: type, nums: list[int], expected: bool):
36+
result = run_can_partition(solution_class, nums)
3637
assert_can_partition(result, expected)

leetcode/validate_binary_search_tree/test_solution.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from leetcode_py.test_utils import logged_test
44

55
from .helpers import assert_is_valid_bst, run_is_valid_bst
6-
from .solution import Solution
6+
from .solution import Solution, SolutionBFS, SolutionDFS
77

88

99
class TestValidateBinarySearchTree:
1010
def setup_method(self):
1111
self.solution = Solution()
1212

1313
@logged_test
14+
@pytest.mark.parametrize("solution_class", [Solution, SolutionDFS, SolutionBFS])
1415
@pytest.mark.parametrize(
1516
"root_list, expected",
1617
[
@@ -28,6 +29,6 @@ def setup_method(self):
2829
([3, 1, 5, 0, 2, 4, 6], True),
2930
],
3031
)
31-
def test_is_valid_bst(self, root_list: list[int | None], expected: bool):
32-
result = run_is_valid_bst(Solution, root_list)
32+
def test_is_valid_bst(self, solution_class: type, root_list: list[int | None], expected: bool):
33+
result = run_is_valid_bst(solution_class, root_list)
3334
assert_is_valid_bst(result, expected)

0 commit comments

Comments
 (0)