File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Test cases for linked list operations.
3
+ """
4
+
5
+ import unittest
6
+
7
+ from src .linked_list import ListNode , reverse_linked_list
8
+
9
+
10
+ class TestLinkedList (unittest .TestCase ):
11
+ def test_reverse_linked_list (self ):
12
+ """Test reversing a normal linked list with multiple nodes [1->2->3]."""
13
+ head = ListNode (1 )
14
+ head .next = ListNode (2 )
15
+ head .next .next = ListNode (3 )
16
+
17
+ reversed_head = reverse_linked_list (head )
18
+
19
+ self .assertEqual (reversed_head .val , 3 )
20
+ self .assertEqual (reversed_head .next .val , 2 )
21
+ self .assertEqual (reversed_head .next .next .val , 1 )
22
+ self .assertIsNone (reversed_head .next .next .next )
23
+
24
+ def test_reverse_single_node (self ):
25
+ """Test reversing a linked list with a single node [1]."""
26
+ head = ListNode (1 )
27
+ reversed_head = reverse_linked_list (head )
28
+
29
+ self .assertEqual (reversed_head .val , 1 )
30
+ self .assertIsNone (reversed_head .next )
31
+
32
+ def test_reverse_empty_list (self ):
33
+ """Test reversing an empty linked list."""
34
+ reversed_head = reverse_linked_list (None )
35
+ self .assertIsNone (reversed_head )
You can’t perform that action at this time.
0 commit comments