Finish problem 0002-add-two-numbers
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import pytest
|
||||
from solution import ListNode, Solution
|
||||
|
||||
|
||||
def build(vals):
|
||||
head = None
|
||||
for v in reversed(vals):
|
||||
head = ListNode(v, head)
|
||||
return head
|
||||
|
||||
|
||||
def to_list(node):
|
||||
out = []
|
||||
while node:
|
||||
out.append(node.val)
|
||||
node = node.next
|
||||
return out
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"l1,l2,expected",
|
||||
[
|
||||
([2, 4, 3], [5, 6, 4], [7, 0, 8]),
|
||||
([0], [0], [0]),
|
||||
([9, 9, 9, 9, 9, 9, 9], [9, 9, 9, 9], [8, 9, 9, 9, 0, 0, 0, 1]),
|
||||
],
|
||||
)
|
||||
def test_add_two_numbers(l1, l2, expected):
|
||||
result = Solution().addTwoNumbers(build(l1), build(l2))
|
||||
assert to_list(result) == expected
|
||||
Reference in New Issue
Block a user