Skip to content

Commit 720aab2

Browse files
authored
Added tests 1, 2, 3
1 parent c1298da commit 720aab2

File tree

7 files changed

+137
-80
lines changed

7 files changed

+137
-80
lines changed

README.md

Lines changed: 79 additions & 79 deletions
Large diffs are not rendered by default.

src/main/python/g0001_0100/s0001_two_sum/Solution_test.py renamed to src/main/python/g0001_0100/s0001_two_sum/Solution0001_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from Solution import Solution
2+
from Solution0001 import Solution
33

44
class TestSolution(unittest.TestCase):
55
def test_twoSum(self):

src/main/python/g0001_0100/s0002_add_two_numbers/Solution.py renamed to src/main/python/g0001_0100/s0002_add_two_numbers/Solution0002.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# #Top_Interview_150_Linked_List #Big_O_Time_O(max(N,M))_Space_O(max(N,M))
44
# #AI_can_be_used_to_solve_the_task #2025_07_22_Time_0_ms_(100.00%)_Space_17.84_MB_(56.69%)
55

6+
from typing import Optional
7+
8+
class ListNode:
9+
def __init__(self, val=0, next=None):
10+
self.val = val
11+
self.next = next
12+
613
# Definition for singly-linked list.
714
# class ListNode:
815
# def __init__(self, val=0, next=None):
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import unittest
2+
from Solution0002 import Solution, ListNode
3+
4+
def construct_linked_list(arr):
5+
if not arr:
6+
return None
7+
head = ListNode(arr[0])
8+
curr = head
9+
for val in arr[1:]:
10+
curr.next = ListNode(val)
11+
curr = curr.next
12+
return head
13+
14+
def linked_list_to_str(node):
15+
vals = []
16+
while node:
17+
vals.append(str(node.val))
18+
node = node.next
19+
return ', '.join(vals)
20+
21+
class TestSolution(unittest.TestCase):
22+
def test_addTwoNumbers(self):
23+
listNode1 = construct_linked_list([2, 4, 3])
24+
listNode2 = construct_linked_list([5, 6, 4])
25+
result = Solution().addTwoNumbers(listNode1, listNode2)
26+
self.assertEqual(linked_list_to_str(result), "7, 0, 8")
27+
28+
def test_addTwoNumbers2(self):
29+
listNode1 = ListNode(0)
30+
listNode2 = ListNode(0)
31+
result = Solution().addTwoNumbers(listNode1, listNode2)
32+
self.assertEqual(linked_list_to_str(result), "0")
33+
34+
def test_addTwoNumbers3(self):
35+
listNode1 = construct_linked_list([9, 9, 9, 9, 9, 9, 9])
36+
listNode2 = construct_linked_list([9, 9, 9, 9])
37+
result = Solution().addTwoNumbers(listNode1, listNode2)
38+
self.assertEqual(linked_list_to_str(result), "8, 9, 9, 9, 0, 0, 0, 1")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0003 import Solution
3+
4+
class TestSolution(unittest.TestCase):
5+
def test_lengthOfLongestSubstring(self):
6+
self.assertEqual(Solution().lengthOfLongestSubstring("abcabcbb"), 3)
7+
8+
def test_lengthOfLongestSubstring2(self):
9+
self.assertEqual(Solution().lengthOfLongestSubstring("bbbbb"), 1)
10+
11+
def test_lengthOfLongestSubstring3(self):
12+
self.assertEqual(Solution().lengthOfLongestSubstring("pwwkew"), 3)

0 commit comments

Comments
 (0)