2025-04-19 11:15:18 -05:00
|
|
|
/*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*
|
|
|
|
|
* -----------------------------------------------------------------------------
|
|
|
|
|
* File: Main.c
|
|
|
|
|
* Description:
|
|
|
|
|
* Executes all tests.
|
|
|
|
|
*
|
|
|
|
|
* Author: Mineplay
|
|
|
|
|
* -----------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#include <stdio.h>
|
2025-04-19 15:14:30 -05:00
|
|
|
#include <Fledasty/Core/Queue.h>
|
2025-04-23 05:08:00 -05:00
|
|
|
#include <Fledasty/Core/Stack.h>
|
2025-04-24 10:34:57 -05:00
|
|
|
#include <Fledasty/Core/DynamicArray.h>
|
2025-04-25 14:44:24 -05:00
|
|
|
#include <Fledasty/Core/LinkedList.h>
|
2025-04-26 08:56:56 -05:00
|
|
|
#include <Fledasty/Core/DoublyLinkedList.h>
|
2025-04-19 11:15:18 -05:00
|
|
|
|
|
|
|
|
int main() {
|
2025-04-19 15:14:30 -05:00
|
|
|
FledastyQueue test_queue;
|
2025-04-24 04:49:52 -05:00
|
|
|
fledasty_queue_initialize(&test_queue, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));
|
2025-04-20 09:08:59 -05:00
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i += 1) {
|
2025-04-21 13:10:44 -05:00
|
|
|
fledasty_queue_push(&test_queue, &i);
|
2025-04-20 09:08:59 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-23 07:14:45 -05:00
|
|
|
int *peeked_queue_data = (int*)fledasty_queue_peek(&test_queue);
|
2025-04-24 17:51:53 -05:00
|
|
|
printf("Queue peeked: %d\n", *peeked_queue_data);
|
2025-04-21 15:14:06 -05:00
|
|
|
|
2025-04-21 15:30:49 -05:00
|
|
|
for (int i = test_queue.size; i > 0; i -= 1) {
|
|
|
|
|
int *popped_data = (int*)fledasty_queue_pop(&test_queue);
|
2025-04-24 17:51:53 -05:00
|
|
|
printf("Queue popped: %d\n", *popped_data);
|
2025-04-21 15:30:49 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-22 15:23:51 -05:00
|
|
|
if (fledasty_queue_is_empty(&test_queue)) {
|
|
|
|
|
printf("Queue is empty\n");
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-19 15:14:30 -05:00
|
|
|
fledasty_queue_destroy(&test_queue);
|
|
|
|
|
|
2025-04-23 05:08:00 -05:00
|
|
|
FledastyStack test_stack;
|
2025-04-23 17:40:38 -05:00
|
|
|
fledasty_stack_initialize(&test_stack, (int[]){ 11, 12, 13, 14, 15 }, 5, sizeof(int));
|
2025-04-23 05:08:00 -05:00
|
|
|
|
2025-04-23 05:33:10 -05:00
|
|
|
for (int i = 0; i < 10; i += 1) {
|
|
|
|
|
fledasty_stack_push(&test_stack, &i);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 07:14:45 -05:00
|
|
|
int *peeked_stack_data = (int*)fledasty_stack_peek(&test_stack);
|
2025-04-24 17:51:53 -05:00
|
|
|
printf("Stack peeked: %d\n", *peeked_stack_data);
|
2025-04-23 07:14:45 -05:00
|
|
|
|
2025-04-23 12:05:36 -05:00
|
|
|
for (int i = test_stack.size; i > 0; i -= 1) {
|
|
|
|
|
int *popped_data = (int*)fledasty_stack_pop(&test_stack);
|
2025-04-24 17:51:53 -05:00
|
|
|
printf("Stack popped: %d\n", *popped_data);
|
2025-04-23 12:05:36 -05:00
|
|
|
}
|
|
|
|
|
|
2025-04-23 05:11:25 -05:00
|
|
|
if (fledasty_stack_is_empty(&test_stack)) {
|
|
|
|
|
printf("Stack is empty\n");
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-23 05:08:00 -05:00
|
|
|
fledasty_stack_destroy(&test_stack);
|
|
|
|
|
|
2025-04-24 10:34:57 -05:00
|
|
|
FledastyDynamicArray test_dynamic_array;
|
|
|
|
|
fledasty_dynamic_array_initialize(&test_dynamic_array, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));
|
2025-04-24 12:40:21 -05:00
|
|
|
for (int i = 0; i < 10; i += 1) {
|
|
|
|
|
fledasty_dynamic_array_append(&test_dynamic_array, &i);
|
|
|
|
|
}
|
2025-04-24 10:34:57 -05:00
|
|
|
|
2025-04-24 17:36:38 -05:00
|
|
|
int insert_value = 18;
|
|
|
|
|
fledasty_dynamic_array_insert_at_index(&test_dynamic_array, 1, &insert_value);
|
|
|
|
|
|
2025-04-24 18:26:33 -05:00
|
|
|
insert_value = 35;
|
2025-04-25 04:34:01 -05:00
|
|
|
int insert_at_value = 11;
|
|
|
|
|
fledasty_dynamic_array_insert_before_value(&test_dynamic_array, &insert_at_value, &insert_value);
|
|
|
|
|
insert_value = 90;
|
|
|
|
|
insert_at_value = 35;
|
|
|
|
|
fledasty_dynamic_array_insert_after_value(&test_dynamic_array, &insert_at_value, &insert_value);
|
2025-04-24 18:26:33 -05:00
|
|
|
|
2025-04-25 05:09:16 -05:00
|
|
|
int remove_value = 15;
|
|
|
|
|
fledasty_dynamic_array_remove_value(&test_dynamic_array, &remove_value);
|
2025-04-25 05:56:32 -05:00
|
|
|
fledasty_dynamic_array_remove_at_index(&test_dynamic_array, test_dynamic_array.size - 2);
|
2025-04-25 05:09:16 -05:00
|
|
|
|
2025-04-24 17:51:53 -05:00
|
|
|
for (int i = 0; i < test_dynamic_array.size; i += 1) {
|
|
|
|
|
int *dynamic_array_data = (int*)fledasty_dynamic_array_get(&test_dynamic_array, i);
|
|
|
|
|
printf("Dynamic array get: %d\n", *dynamic_array_data);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 04:42:15 -05:00
|
|
|
if (fledasty_dynamic_array_has_value(&test_dynamic_array, &insert_value)) {
|
|
|
|
|
printf("Dynamic array contains %d\n", insert_value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 18:26:33 -05:00
|
|
|
if (fledasty_dynamic_array_is_empty(&test_dynamic_array)) {
|
|
|
|
|
printf("Dynamic array is empty\n");
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-24 10:34:57 -05:00
|
|
|
fledasty_dynamic_array_destroy(&test_dynamic_array);
|
2025-04-25 14:44:24 -05:00
|
|
|
|
|
|
|
|
FledastyLinkedList test_linked_list;
|
|
|
|
|
fledasty_linked_list_initialize(&test_linked_list, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));
|
|
|
|
|
|
2025-04-25 15:18:44 -05:00
|
|
|
for (int i = 0; i < 10; i += 1) {
|
|
|
|
|
fledasty_linked_list_append(&test_linked_list, &i);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 17:04:33 -05:00
|
|
|
insert_value = 35;
|
|
|
|
|
fledasty_linked_list_insert_at_index(&test_linked_list, 1, &insert_value);
|
2025-04-25 17:11:35 -05:00
|
|
|
insert_value = 28;
|
|
|
|
|
insert_at_value = 35;
|
|
|
|
|
fledasty_linked_list_insert_before_value(&test_linked_list, &insert_at_value, &insert_value);
|
2025-04-25 17:15:58 -05:00
|
|
|
insert_value = 90;
|
|
|
|
|
fledasty_linked_list_insert_after_value(&test_linked_list, &insert_at_value, &insert_value);
|
2025-04-25 17:04:33 -05:00
|
|
|
|
2025-04-26 05:33:29 -05:00
|
|
|
fledasty_linked_list_remove_at_index(&test_linked_list, 2);
|
2025-04-26 07:32:29 -05:00
|
|
|
remove_value = 0;
|
|
|
|
|
fledasty_linked_list_remove_value(&test_linked_list, &remove_value);
|
2025-04-26 05:33:29 -05:00
|
|
|
|
2025-04-25 15:48:09 -05:00
|
|
|
FledastyLinkedListNode *test_linked_list_node = test_linked_list.start;
|
2025-04-25 16:11:13 -05:00
|
|
|
for (int i = 0; i < test_linked_list.size; i += 1) {
|
2025-04-25 15:48:09 -05:00
|
|
|
printf("Linked list get: %d\n", *(int*)test_linked_list_node->value);
|
|
|
|
|
test_linked_list_node = test_linked_list_node->next;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-26 04:50:00 -05:00
|
|
|
if (fledasty_linked_list_has_value(&test_linked_list, &insert_value)) {
|
|
|
|
|
printf("Linked list contains %d\n", insert_value);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 16:11:13 -05:00
|
|
|
if (fledasty_linked_list_is_empty(&test_linked_list)) {
|
|
|
|
|
printf("Linked list is empty\n");
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-25 14:44:24 -05:00
|
|
|
fledasty_linked_list_destroy(&test_linked_list);
|
2025-04-26 08:56:56 -05:00
|
|
|
|
|
|
|
|
FledastyDoublyLinkedList test_doubly_linked_list;
|
|
|
|
|
fledasty_doubly_linked_list_initialize(&test_doubly_linked_list, (int[]){11, 12, 13, 14, 15}, 5, sizeof(int));
|
|
|
|
|
|
2025-04-26 09:20:11 -05:00
|
|
|
for (int i = 0; i < 10; i += 1) {
|
|
|
|
|
fledasty_doubly_linked_list_append(&test_doubly_linked_list, &i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FledastyDoublyLinkedListNode *test_doubly_linked_list_node = test_doubly_linked_list.start;
|
|
|
|
|
for (int i = 0; i < test_doubly_linked_list.size; i += 1) {
|
|
|
|
|
printf("Doubly linked list get: %d\n", *(int*)test_doubly_linked_list_node->value);
|
|
|
|
|
test_doubly_linked_list_node = test_doubly_linked_list_node->next;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-26 08:56:56 -05:00
|
|
|
fledasty_doubly_list_destroy(&test_doubly_linked_list);
|
2025-04-19 15:14:30 -05:00
|
|
|
printf("Done\n");
|
2025-04-19 11:15:18 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|