@@ -125,6 +125,11 @@ ZTEST(min_heap_api, test_insert)
125
125
ret = min_heap_push (& my_heap_gt , & elements [i ]);
126
126
zassert_ok (ret , "min_heap_push failed" );
127
127
}
128
+
129
+ /* Try to push one more element to the now full heap */
130
+ ret = min_heap_push (& my_heap_gt , & elements [0 ]);
131
+ zassert_equal (ret , - ENOMEM , "push on full heap should return -ENOMEM" );
132
+
128
133
validate_heap_order_gt (& my_heap_gt );
129
134
}
130
135
@@ -152,6 +157,7 @@ ZTEST(min_heap_api, test_peek_and_pop)
152
157
zassert_equal (peek_key , pop .key , "Peek/pop error" );
153
158
zassert_equal (pop .key , LOWEST_PRIORITY_LS , "heap error %d" , pop .key );
154
159
validate_heap_order_ls (& runtime_heap );
160
+ zassert_is_null (min_heap_peek (& runtime_heap ), "peek on empty heap should return NULL" );
155
161
}
156
162
157
163
ZTEST (min_heap_api , test_find_and_remove )
@@ -165,13 +171,23 @@ ZTEST(min_heap_api, test_find_and_remove)
165
171
}
166
172
167
173
int target_key = 5 ;
174
+ int wrong_key = 100 ;
168
175
size_t index ;
169
- struct data removed , * found ;
176
+ struct data removed , * found , * found_ignore_index , * not_found ;
170
177
171
178
found = min_heap_find (& my_heap , match_key , & target_key , & index );
179
+ found_ignore_index = min_heap_find (& my_heap , match_key , & target_key , NULL );
180
+ not_found = min_heap_find (& my_heap , match_key , & wrong_key , & index );
172
181
173
182
zassert_not_null (found , "min_heap_find failure" );
183
+ zassert_not_null (found_ignore_index , "min_heap_find failure" );
184
+ zassert_is_null (not_found , "min_heap_find failure" );
185
+ zassert_equal (found -> key , target_key , "Found wrong element" );
174
186
min_heap_remove (& my_heap , index , & removed );
187
+ zassert_false (min_heap_is_empty (& my_heap ), "Heap should not be empty" );
188
+ min_heap_remove (& my_heap , HEAP_CAPACITY , & removed );
189
+ zassert_false (min_heap_remove (& my_heap , HEAP_CAPACITY , & removed ),
190
+ "remove with invalid index should return false" );
175
191
validate_heap_order_ls (& my_heap );
176
192
zassert_true (min_heap_is_empty (& my_heap ), "Empty check fail" );
177
193
}
0 commit comments