Skip to content

Commit 7e621c2

Browse files
committed
✅ Add doctests to string conversion functions
1 parent ed7c9b5 commit 7e621c2

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

strings/min_cost_string_conversion.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ def compute_transform_tables(
1818
insert_cost: int,
1919
) -> tuple[list[list[int]], list[list[str]]]:
2020
"""
21-
Finds the most cost efficient sequence
21+
Finds the most cost-efficient sequence
2222
for converting one string into another.
2323
24+
>>> compute_transform_tables("", "", 1, 2, 3, 3)
25+
([[0]], [['0']])
26+
2427
>>> costs, operations = compute_transform_tables("cat", "cut", 1, 2, 3, 3)
2528
>>> costs[0][:4]
2629
[0, 3, 6, 9]
@@ -30,10 +33,8 @@ def compute_transform_tables(
3033
['0', 'Ic', 'Iu', 'It']
3134
>>> operations[3][:4]
3235
['Dt', 'Dt', 'Rtu', 'Ct']
33-
34-
>>> compute_transform_tables("", "", 1, 2, 3, 3)
35-
([[0]], [['0']])
3636
"""
37+
3738
source_seq = list(source_string)
3839
destination_seq = list(destination_string)
3940
len_source_seq = len(source_seq)
@@ -86,18 +87,13 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]:
8687
>>> assemble_transformation(ops, x, y)
8788
['Cc', 'Rau', 'Ct']
8889
89-
>>> ops1 = [['0']]
90-
>>> x1 = len(ops1) - 1
91-
>>> y1 = len(ops1[0]) - 1
92-
>>> assemble_transformation(ops1, x1, y1)
90+
>>> assemble_transformation([['0']], 0, 0)
9391
[]
9492
9593
>>> ops2 = [['0', 'I1', 'I2', 'I3'],
9694
... ['D1', 'C1', 'I2', 'I3'],
9795
... ['D2', 'D2', 'R23', 'R23']]
98-
>>> x2 = len(ops2) - 1
99-
>>> y2 = len(ops2[0]) - 1
100-
>>> assemble_transformation(ops2, x2, y2)
96+
>>> assemble_transformation(ops2, 2, 3)
10197
['C1', 'I2', 'R23']
10298
"""
10399
if i == 0 and j == 0:

0 commit comments

Comments
 (0)