ixueaedu 2 years ago
parent
commit
1391f45869
2 changed files with 13 additions and 18 deletions
  1. 9 18
      draft.py
  2. 4 0
      merge_two_lists.py

+ 9 - 18
draft.py

@@ -1,18 +1,9 @@
-from Cython.Compiler.ExprNodes import ListNode
-class Node:
-    def __init__(self,cargo = None, next = None):
-        self.cargo = cargo
-        self.next = next
-    def __str__(self):
-        #测试基本功能,输出字符串
-        return str(self.cargo)
-
-def printBackward(lists):
-    if lists == None:
-        return
-    head = lists
-    tail= lists.next
-    print(head,tail)
-    printBackward(tail)
-    print(head,tail)
-print(printBackward([123]))
+import pytest
+@pytest.mark.parametrize(
+    "list1, list2, expect",
+    [
+        ([1, 2, 4], [1, 3, 4], [1, 1, 2, 3, 4, 4])
+    ]
+)
+def test_cases(list1, list2, expect):
+    assert mergeTwoLists(list1, list2) == expect

+ 4 - 0
merge_two_lists.py

@@ -1,4 +1,5 @@
 from typing import Optional
+import pytest
 # from Cython.Compiler.ExprNodes import ListNode
 
 class ListNode:
@@ -23,3 +24,6 @@ class Solution:
             pre.next = list1 if list1 else list2
 
             return newList
+
+if __name__ == "__main__":
+    print(mergeTwoLists([1, 2, 4], [1, 3, 4]))