Skip to content

Commit 50aca04

Browse files
authored
feat: increase test coverage of longest_common_subsequence to 75% (#11777)
1 parent 5a8655d commit 50aca04

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

dynamic_programming/longest_common_subsequence.py

+18
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ def longest_common_subsequence(x: str, y: str):
2828
(2, 'ph')
2929
>>> longest_common_subsequence("computer", "food")
3030
(1, 'o')
31+
>>> longest_common_subsequence("", "abc") # One string is empty
32+
(0, '')
33+
>>> longest_common_subsequence("abc", "") # Other string is empty
34+
(0, '')
35+
>>> longest_common_subsequence("", "") # Both strings are empty
36+
(0, '')
37+
>>> longest_common_subsequence("abc", "def") # No common subsequence
38+
(0, '')
39+
>>> longest_common_subsequence("abc", "abc") # Identical strings
40+
(3, 'abc')
41+
>>> longest_common_subsequence("a", "a") # Single character match
42+
(1, 'a')
43+
>>> longest_common_subsequence("a", "b") # Single character no match
44+
(0, '')
45+
>>> longest_common_subsequence("abcdef", "ace") # Interleaved subsequence
46+
(3, 'ace')
47+
>>> longest_common_subsequence("ABCD", "ACBD") # No repeated characters
48+
(3, 'ABD')
3149
"""
3250
# find the length of strings
3351

0 commit comments

Comments
 (0)