@@ -9,13 +9,6 @@ def setUp(self) -> None:
9
9
self .linked_list = LinkedList ()
10
10
self .sample_data = [1 , 10 , 3 , 8 , 12 , 9 , 4 , 15 , 24 ]
11
11
12
- @mock .patch ('builtins.print' )
13
- def assert_valid_print (self , items , mock_print ):
14
- self .linked_list .print_list ()
15
- mock_print .assert_called_with (
16
- " " .join (map (str , items ))
17
- )
18
-
19
12
def append_items (self , items = None ):
20
13
if items is None :
21
14
items = self .sample_data
@@ -26,6 +19,13 @@ def prepend_items(self):
26
19
for number in self .sample_data :
27
20
self .linked_list .prepend (number )
28
21
22
+ @mock .patch ('builtins.print' )
23
+ def assert_valid_print (self , items , mock_print ):
24
+ self .linked_list .print_list ()
25
+ mock_print .assert_called_with (
26
+ " " .join (map (str , items ))
27
+ )
28
+
29
29
def test_append_empty_linked_list (self ):
30
30
self .assertIsNone (self .linked_list .head )
31
31
self .linked_list .append (15 )
@@ -123,3 +123,39 @@ def test_merge_sort(self):
123
123
list2 .append (item )
124
124
self .linked_list .merge_sorted (list2 )
125
125
self .assert_valid_print (sorted (data1 + data2 ))
126
+
127
+ def test_remove_duplicates (self ):
128
+ data = copy .copy (self .sample_data )
129
+ data .append (data [0 ])
130
+ self .append_items (data )
131
+ self .linked_list .remove_duplicates ()
132
+ self .assert_valid_print (self .sample_data )
133
+
134
+ def test_get_nth_from_last (self ):
135
+ self .append_items ()
136
+ n = 5
137
+ nth_item = self .linked_list .get_nth_from_last (n )
138
+ self .assertEqual (nth_item , self .sample_data [- n ])
139
+
140
+ def test_count_occurrences (self ):
141
+ self .append_items ()
142
+ num = 5
143
+ counted = self .linked_list .count_occurrences (num )
144
+ self .assertEqual (counted , self .sample_data .count (num ))
145
+
146
+ def test_is_palindrome_false (self ):
147
+ self .append_items ()
148
+ self .assertFalse (self .linked_list .is_palindrome ())
149
+
150
+ def test_is_palindrome_true (self ):
151
+ data = copy .copy (self .sample_data )
152
+ data .extend (self .sample_data [::- 1 ])
153
+ self .append_items (data )
154
+ self .assertTrue (self .linked_list .is_palindrome ())
155
+
156
+ def test_move_tail_to_head (self ):
157
+ self .append_items ()
158
+ self .linked_list .move_tail_to_head ()
159
+ self .linked_list .print_list ()
160
+ data = [self .sample_data [- 1 ]] + self .sample_data [:- 1 ]
161
+ self .assert_valid_print (data )
0 commit comments