diff --git a/Makefile b/Makefile index 7c41b43..89a405c 100644 --- a/Makefile +++ b/Makefile @@ -10,12 +10,10 @@ SQ = $(MAIN)/StaticQueue DQ = $(MAIN)/DynamicQueue MAT = $(MAIN)/Matrix UWG1 = $(MAIN)/UndirectedWeightedGraph1 -UWG2 = $(MAIN)/UndirectedWeightedGraph2 #--NEW_DS_DIR EH = $(HELPERS)/ExceptionHandler N = $(HELPERS)/Node V = $(HELPERS)/Vertex -E = $(HELPERS)/Edge #--NEW_HELPER_DIR APP = LIBDS @@ -43,13 +41,11 @@ ED7 = static_queue ED8 = dynamic_queue ED9 = matrix ED10 = undirected_weighted_graph1 -ED11 = undirected_weighted_graph2 #--ADD_NEW_DS #DS12 H1 = exception_handler H2 = node H3 = vertex -H4 = edge #--ADD_NEW_HELPER #H5 @@ -79,8 +75,6 @@ LIBS = -l$(LIB_NAME) -L $(LIB) cp $(EH)/$(MAIN)/$(SRC)/$(H1).c $(APP)/$(AUX)/$(SRC) cp $(N)/$(MAIN)/$(SRC)/$(H2).c $(APP)/$(AUX)/$(SRC) cp $(V)/$(MAIN)/$(SRC)/$(H3).c $(APP)/$(AUX)/$(SRC) - cp $(UWG2)/$(MAIN)/$(SRC)/$(ED11).c $(APP)/$(AUX)/$(SRC) - cp $(E)/$(HELPERS)/$(SRC)/$(H4).c $(APP)/$(AUX)/$(SRC) #--GET_SRC --private-get_headers: @@ -97,8 +91,6 @@ LIBS = -l$(LIB_NAME) -L $(LIB) cp $(EH)/$(MAIN)/$(INCLUDE)/$(H1).h $(APP)/$(INCLUDE) cp $(N)/$(MAIN)/$(INCLUDE)/$(H2).h $(APP)/$(INCLUDE) cp $(V)/$(MAIN)/$(INCLUDE)/$(H3).h $(APP)/$(INCLUDE) - cp $(UWG2)/$(MAIN)/$(INCLUDE)/$(ED11).h $(APP)/$(INCLUDE) - cp $(E)/$(HELPERS)/$(INCLUDE)/$(H4).h $(APP)/$(INCLUDE) #--GET_H --private-get_eds: --private-create_lib --private-get_srcs --private-get_headers @@ -130,8 +122,6 @@ compile: $(APP)/$(AUX)/$(OBJ)/$(ED1).o \ $(APP)/$(AUX)/$(OBJ)/$(H1).o \ $(APP)/$(AUX)/$(OBJ)/$(H2).o \ $(APP)/$(AUX)/$(OBJ)/$(H3).o \ - $(APP)/$(AUX)/$(OBJ)/$(ED11).o \ - $(APP)/$(AUX)/$(OBJ)/$(H4).o \ #--ADD_TO_COMPILE ar -rcs $(APP)/$(LIB)/lib$(LIB_NAME).a $(APP)/$(AUX)/$(OBJ)/*.o rm -rf $(APP)/$(AUX) diff --git a/main/UndirectedWeightedGraph1/main/src/undirected_weighted_graph1.c b/main/UndirectedWeightedGraph1/main/src/undirected_weighted_graph1.c index 08db70b..9432704 100644 --- a/main/UndirectedWeightedGraph1/main/src/undirected_weighted_graph1.c +++ b/main/UndirectedWeightedGraph1/main/src/undirected_weighted_graph1.c @@ -160,7 +160,7 @@ bool UndirectedWeightedGraph1_is_full(void *uwg) { bool UndirectedWeightedGraph1_insert_vertex(UndirectedWeightedGraph1 *uwg, void *data) { if (anyThrows( - 4, + 3, ExceptionHandler_is_null("UndirectedWeightedGraph1_insert_vertex", "Undirected Weighted Graph", (void *) uwg, __SUPPRESS_PRINT_ERROR__), ExceptionHandler_is_null("UndirectedWeightedGraph1_insert_vertex", "Data", data, __SUPPRESS_PRINT_ERROR__), ExceptionHandler_is_full("UndirectedWeightedGraph1_insert_vertex", "Undirected Weighted Graph", (void *) uwg, UndirectedWeightedGraph1_is_full, __SUPPRESS_PRINT_ERROR__) diff --git a/main/UndirectedWeightedGraph2/.info b/main/UndirectedWeightedGraph2/.info deleted file mode 100644 index db004c7..0000000 --- a/main/UndirectedWeightedGraph2/.info +++ /dev/null @@ -1,4 +0,0 @@ -ptd_ds_CircularDoublyLinkedList -pvt_hp_Node -pub_hp_ExceptionHandler -ptd_hp_Edge diff --git a/main/UndirectedWeightedGraph2/Makefile b/main/UndirectedWeightedGraph2/Makefile deleted file mode 100644 index 7cc6352..0000000 --- a/main/UndirectedWeightedGraph2/Makefile +++ /dev/null @@ -1,128 +0,0 @@ -# Directories -MAIN = main -TEST = test -# Generics -APPS = apps -TESTS = tests -BIN = bin -INCLUDE = include -LIB = lib -OBJ = obj -SRC = src -hp_FOLDER_0 = ../../resources/helpers/Node/$(MAIN) -hp_DEP_FOLDER_0_1 = ../../resources/helpers/ExceptionHandler/$(MAIN) -hp_FOLDER_1 = ../../resources/helpers/Edge/$(MAIN) -#--ADD_FOLDER_NEW_hp -ds_FOLDER_0 = ../CircularDoublyLinkedList/$(MAIN) -#--ADD_FOLDER_NEW_ds - -# Names Definition -APP_NAME = app_undirected_weighted_graph2 -LIB_NAME = UWG2 -DS = undirected_weighted_graph2 -TEST_DS = undirected_weighted_graph2.test -UNITY = ../../resources/unity -DEPS = ../../resources/scripts/dependencies -INSTALL = install.sh -hp_0 = node -hp_DEP_0_1 = exception_handler -hp_1 = edge -#--ADD_NEW_hp -ds_0 = circular_doubly_linked_list -#--ADD_NEW_ds -#ds1 -#hp2 - -# Compilation Flags -FLAGS = -O3 -Wall -pedantic -Warray-bounds -Werror -LIBS = -l$(LIB_NAME) -L $(MAIN)/$(LIB) - ---private-create_folders: - mkdir $(MAIN)/$(LIB) - mkdir $(MAIN)/$(OBJ) - mkdir $(MAIN)/$(BIN) - mkdir $(TEST)/$(BIN) - ---private-get_external_lib: - cp $(ds_FOLDER_0)/$(SRC)/$(ds_0).c $(MAIN)/$(SRC)/ - cp $(ds_FOLDER_0)/$(INCLUDE)/$(ds_0).h $(MAIN)/$(INCLUDE)/ - cp $(hp_FOLDER_0)/$(SRC)/$(hp_0).c $(MAIN)/$(SRC)/ - cp $(hp_FOLDER_0)/$(INCLUDE)/$(hp_0).h $(MAIN)/$(INCLUDE)/ - cp $(hp_DEP_FOLDER_0_1)/$(SRC)/$(hp_DEP_0_1).c $(MAIN)/$(SRC)/ - cp $(hp_DEP_FOLDER_0_1)/$(INCLUDE)/$(hp_DEP_0_1).h $(MAIN)/$(INCLUDE)/ - cp $(hp_FOLDER_1)/$(SRC)/$(hp_1).c $(MAIN)/$(SRC)/ - cp $(hp_FOLDER_1)/$(INCLUDE)/$(hp_1).h $(MAIN)/$(INCLUDE)/ -#--ADD_GET_NEW_LIB - cp $(UNITY)/$(INCLUDE)/* $(MAIN)/$(INCLUDE)/ - cp $(UNITY)/$(SRC)/* $(MAIN)/$(SRC)/ - -pack: clean_all --private-create_folders --private-get_external_lib \ - $(MAIN)/$(OBJ)/$(DS).o \ - $(MAIN)/$(OBJ)/$(ds_0).o \ - $(MAIN)/$(OBJ)/$(hp_0).o \ - $(MAIN)/$(OBJ)/$(hp_DEP_0_1).o \ - $(MAIN)/$(OBJ)/$(hp_1).o \ -#--ADD_TO_PACK - ar -rcs $(MAIN)/$(LIB)/lib$(LIB_NAME).a $(MAIN)/$(OBJ)/*.o - -compile_apps: $(MAIN)/$(BIN)/$(APP_NAME) - -compile_test: $(MAIN)/$(OBJ)/$(DS).o \ - $(MAIN)/$(OBJ)/unity.o \ - $(TEST)/$(BIN)/$(TEST_DS) \ - $(MAIN)/$(OBJ)/$(ds_0).o \ - $(MAIN)/$(OBJ)/$(hp_0).o \ - $(MAIN)/$(OBJ)/$(hp_DEP_0_1).o \ - $(MAIN)/$(OBJ)/$(hp_1).o \ -#--ADD_TO_COMPILE_TEST - -run_apps: pack compile_apps - $(MAIN)/$(BIN)/$(APP_NAME) - make clean_external - -run_tests: clean_all pack compile_test - $(TEST)/$(BIN)/$(TEST_DS) - make clean_all - -install_ds: - $(DEPS)/$(INSTALL) -ds - -install_helper: - $(DEPS)/$(INSTALL) -h - -install: - $(DEPS)/$(INSTALL) -$(filter-out $@,$(MAKECMDGOALS)) - -clean_all: clean_libs clean_apps clean_test clean_external - -clean_libs: - rm -rf $(MAIN)/$(OBJ) $(MAIN)/$(LIB) - -clean_apps: - rm -rf $(MAIN)/$(BIN) - -clean_test: - rm -rf $(TEST)/$(BIN) - -clean_external: - rm -rf $(MAIN)/$(SRC)/$(ds_0).c - rm -rf $(MAIN)/$(INCLUDE)/$(ds_0).h - rm -rf $(MAIN)/$(SRC)/$(hp_0).c - rm -rf $(MAIN)/$(INCLUDE)/$(hp_0).h - rm -rf $(MAIN)/$(SRC)/$(hp_DEP_0_1).c - rm -rf $(MAIN)/$(INCLUDE)/$(hp_DEP_0_1).h - rm -rf $(MAIN)/$(SRC)/$(hp_1).c - rm -rf $(MAIN)/$(INCLUDE)/$(hp_1).h -#--ADD_TO_CLEAN - rm -rf $(MAIN)/$(SRC)/unity.c - rm -rf $(MAIN)/$(INCLUDE)/unity.h - rm -rf $(MAIN)/$(INCLUDE)/unity_internals.h - -$(MAIN)/$(OBJ)/%.o: $(MAIN)/$(SRC)/%.c $(MAIN)/$(INCLUDE)/%.h - gcc $(FLAGS) -c $< -I $(MAIN)/$(INCLUDE) -o $@ - -$(MAIN)/$(BIN)/%: $(MAIN)/$(APPS)/%.c - gcc $(FLAGS) $< $(LIBS) -I $(MAIN)/$(INCLUDE) -o $@ - -$(TEST)/$(BIN)/%: $(TEST)/$(TESTS)/%.c - gcc $(FLAGS) $< $(MAIN)/$(OBJ)/*.o -I $(MAIN)/$(INCLUDE) -o $@ diff --git a/main/UndirectedWeightedGraph2/main/apps/app_undirected_weighted_graph2.c b/main/UndirectedWeightedGraph2/main/apps/app_undirected_weighted_graph2.c deleted file mode 100644 index 008e259..0000000 --- a/main/UndirectedWeightedGraph2/main/apps/app_undirected_weighted_graph2.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include "../include/undirected_weighted_graph2.h" - -int main() { - -// char *command = "make run_tests"; -// int executed = system(command); -// if (executed != 0) return EXIT_FAILURE; - - UndirectedWeightedGraph2 *uwg = UndirectedWeightedGraph2_create(); - int a = 1, b = 2, c = 3; - UndirectedWeightedGraph2_insert_Vertex(uwg, &a); - UndirectedWeightedGraph2_insert_Vertex(uwg, &b); - UndirectedWeightedGraph2_insert_Vertex(uwg, &c); - - UndirectedWeightedGraph2_add_Edge(uwg, 0, 1, 1.1); - UndirectedWeightedGraph2_add_Edge(uwg, 0, 2, 2.2); - UndirectedWeightedGraph2_add_Edge(uwg, 1, 2, 3.3); - - float edge_0_1 = UndirectedWeightedGraph2_get_weight(uwg, 0, 1); - float edge_0_2 = UndirectedWeightedGraph2_get_weight(uwg, 0, 2); - float edge_1_2 = UndirectedWeightedGraph2_get_weight(uwg, 1, 2); - - printf("Edge(0, 1): %f\n", edge_0_1); - printf("Edge(0, 2): %f\n", edge_0_2); - printf("Edge(1, 2): %f\n", edge_1_2); - - int d = 4, e = 5; - UndirectedWeightedGraph2_insert_Vertex(uwg, &d); - UndirectedWeightedGraph2_insert_Vertex(uwg, &e); - UndirectedWeightedGraph2_add_Edge(uwg, 3, 0, 4.4); - UndirectedWeightedGraph2_add_Edge(uwg, 3, 1, 4.4); - UndirectedWeightedGraph2_add_Edge(uwg, 3, 2, 4.4); - - float edge_0_1_p = UndirectedWeightedGraph2_get_weight(uwg, 0, 1); - float edge_0_2_p = UndirectedWeightedGraph2_get_weight(uwg, 0, 2); - float edge_1_2_p = UndirectedWeightedGraph2_get_weight(uwg, 1, 2); - float edge_0_3 = UndirectedWeightedGraph2_get_weight(uwg, 3, 0); - float edge_1_3 = UndirectedWeightedGraph2_get_weight(uwg, 3, 1); - float edge_2_3 = UndirectedWeightedGraph2_get_weight(uwg, 3, 2); - - printf("Edge(0, 1): %f\n", edge_0_1_p); - printf("Edge(0, 2): %f\n", edge_0_2_p); - printf("Edge(1, 2): %f\n", edge_1_2_p); - printf("Edge(0, 3): %f\n", edge_0_3); - printf("Edge(1, 3): %f\n", edge_1_3); - printf("Edge(2, 3): %f\n", edge_2_3); - - UndirectedWeightedGraph2_add_Edge(uwg, 3, 2, 4.4); - - UndirectedWeightedGraph2_set_weight(uwg, 3, 2, 99.99); - float edge_2_3_p = UndirectedWeightedGraph2_get_weight(uwg, 3, 2); - printf("Edge(2, 3): %f\n", edge_2_3_p); - - float edge_0_2_p_p = UndirectedWeightedGraph2_get_weight(uwg, 2, 0); - printf("Edge(0, 2): %f\n", edge_0_2_p_p); - - UndirectedWeightedGraph2_remove_Edge(uwg, 0, 2); - float edge_0_2_p_p_p = UndirectedWeightedGraph2_get_weight(uwg, 0, 2); - printf("Edge(0, 2): %f\n", edge_0_2_p_p_p); - - float edge_0_1_p_ = UndirectedWeightedGraph2_get_weight(uwg, 0, 1); - float edge_0_2_p_ = UndirectedWeightedGraph2_get_weight(uwg, 0, 2); - float edge_0_3_p_ = UndirectedWeightedGraph2_get_weight(uwg, 0, 3); - printf("Edge(0, 1): %f\n", edge_0_1_p_); - printf("Edge(0, 2): %f\n", edge_0_2_p_); - printf("Edge(0, 3): %f\n", edge_0_3_p_); - UndirectedWeightedGraph2_remove_Vertex(uwg, 0); - float edge_0_1_p__ = UndirectedWeightedGraph2_get_weight(uwg, 0, 1); - float edge_0_2_p__ = UndirectedWeightedGraph2_get_weight(uwg, 0, 2); - float edge_0_3_p__ = UndirectedWeightedGraph2_get_weight(uwg, 0, 3); - printf("Edge(0, 1): %f\n", edge_0_1_p__); - printf("Edge(0, 2): %f\n", edge_0_2_p__); - printf("Edge(0, 3): %f\n", edge_0_3_p__); - - return EXIT_SUCCESS; -} diff --git a/main/UndirectedWeightedGraph2/main/include/undirected_weighted_graph2.h b/main/UndirectedWeightedGraph2/main/include/undirected_weighted_graph2.h deleted file mode 100644 index 35a709d..0000000 --- a/main/UndirectedWeightedGraph2/main/include/undirected_weighted_graph2.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef UNDIRECTED_WEIGHTED_GRAPH2_H -#define UNDIRECTED_WEIGHTED_GRAPH2_H -#include "exception_handler.h" -//#--ADD_TO_INCLUDE - -#include -#include - -#ifdef __DEFAULT_FLOAT__ - #undef __DEFAULT_FLOAT__ -#endif -#ifdef __DEFAULT_SIZE_T__ - #undef __DEFAULT_SIZE_T__ -#endif -#ifdef __DEFAULT_BOOL__ - #undef __DEFAULT_BOOL__ -#endif -#ifdef __NOT_DEFAULT_BOOL__ - #undef __NOT_DEFAULT_BOOL__ -#endif -#ifdef __DEFAULT_PTR__ - #undef __DEFAULT_PTR__ -#endif -#ifdef __TYPE_COMPARE_FUNCTION_NAME__ - #undef __TYPE_COMPARE_FUNCTION_NAME__ -#endif -#ifdef __TYPE_COMPARE_FUNCTION_SIGNATURE__ - #undef __TYPE_COMPARE_FUNCTION_SIGNATURE__ -#endif -#ifdef __TYPE_PRINT_FUNCTION_NAME__ - #undef __TYPE_PRINT_FUNCTION_NAME__ -#endif -#ifdef __TYPE_PRINT_FUNCTION_SIGNATURE__ - #undef __TYPE_PRINT_FUNCTION_SIGNATURE__ -#endif - -#define __DEFAULT_FLOAT__ 0.0 -#define __DEFAULT_SIZE_T__ 0 -#define __DEFAULT_BOOL__ false -#define __NOT_DEFAULT_BOOL__ true -#define __DEFAULT_PTR__ NULL -#define __TYPE_COMPARE_FUNCTION_NAME__ type_compare_func -#define __TYPE_COMPARE_FUNCTION_SIGNATURE__ int (*__TYPE_COMPARE_FUNCTION_NAME__)(void *data1, void *data2) -#define __TYPE_PRINT_FUNCTION_NAME__ type_print_func -#define __TYPE_PRINT_FUNCTION_SIGNATURE__ void (*__TYPE_PRINT_FUNCTION_NAME__)(void *data) - -#define SIZE_OF_UNDIRECTED_WEIGHTED_GRAPH2_TYPE size_of_undirected_weighted_graph2_type - -extern const size_t size_of_undirected_weighted_graph2_type; - -typedef struct _undirected_weighted_graph2 UndirectedWeightedGraph2; - -UndirectedWeightedGraph2 *UndirectedWeightedGraph2_create(); - -bool UndirectedWeightedGraph2_insert_Vertex(UndirectedWeightedGraph2 *uwg, void *data); - -bool UndirectedWeightedGraph2_add_Edge(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index, float weight); - -float UndirectedWeightedGraph2_get_weight(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index); - -bool UndirectedWeightedGraph2_set_weight(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index, float new_weight); - -bool UndirectedWeightedGraph2_is_empty(void *uwg); - -bool UndirectedWeightedGraph2_remove_Vertex(UndirectedWeightedGraph2 *uwg, size_t vertex_index); - -bool UndirectedWeightedGraph2_remove_Edge(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index); - -#endif diff --git a/main/UndirectedWeightedGraph2/main/src/undirected_weighted_graph2.c b/main/UndirectedWeightedGraph2/main/src/undirected_weighted_graph2.c deleted file mode 100644 index 0d7491c..0000000 --- a/main/UndirectedWeightedGraph2/main/src/undirected_weighted_graph2.c +++ /dev/null @@ -1,158 +0,0 @@ -#include "../include/circular_doubly_linked_list.h" -#include "../include/edge.h" -//#--ADD_TO_INCLUDE -#include "../include/undirected_weighted_graph2.h" - -typedef struct _undirected_weighted_graph2 { - CircularDoublyLinkedList *vertices; - Edge *edges; -} UndirectedWeightedGraph2; - -const size_t size_of_undirected_weighted_graph2_type = sizeof(UndirectedWeightedGraph2); - -void _set_indexes_correctly(size_t *src_index, size_t source_vertex_index, size_t *dest_index, size_t destination_vertex_index) { - if (source_vertex_index < destination_vertex_index) { - *src_index = source_vertex_index; - *dest_index = destination_vertex_index; - return; - } - *src_index = destination_vertex_index; - *dest_index = source_vertex_index; -} - -ExceptionResponse *UndirectedWeightedGraph2_already_has_edge(char *function, bool already_added, bool suppress) { - bool throws = false; - char *error_message = ""; - if (already_added) { - throws = true; - error_message = ExceptionHandler_build_error_message(function, "Edge", " already added.\n"); - } - return ExceptionHandler_create(throws, error_message, suppress); -} - -UndirectedWeightedGraph2 *UndirectedWeightedGraph2_create() { - UndirectedWeightedGraph2 *uwg = (UndirectedWeightedGraph2 *) calloc(1, size_of_undirected_weighted_graph2_type); - uwg->vertices = CircularDoublyLinkedList_create(); - uwg->edges = __DEFAULT_PTR__; - return uwg; -} - -bool UndirectedWeightedGraph2_insert_Vertex(UndirectedWeightedGraph2 *uwg, void *data) { - if (anyThrows( - 2, - ExceptionHandler_is_null("UndirectedWeightedGraph2_add_Vertex", "Undirected Weighted Graph", uwg, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_null("UndirectedWeightedGraph2_add_Vertex", "Data", data, __SUPPRESS_PRINT_ERROR__) - ) || - anyThrows( - 1, - ExceptionHandler_is_null("UndirectedWeightedGraph2_add_Vertex", "Undirected Weighted Graph::Vertices", uwg->vertices, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - CircularDoublyLinkedList *vertex = CircularDoublyLinkedList_create(); - CircularDoublyLinkedList_add_first(vertex, data); - return CircularDoublyLinkedList_add_first(uwg->vertices, vertex); -} - -bool UndirectedWeightedGraph2_add_Edge(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index, float weight) { - if (anyThrows( - 1, - ExceptionHandler_is_null("UndirectedWeightedGraph2_add_Edge", "Undirected Weighted Graph", uwg, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - size_t max_index = CircularDoublyLinkedList_size(uwg->vertices) - 1; - if (anyThrows( - 2, - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_add_Edge", "Source Vertex", source_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_add_Edge", "Destination Vertex", destination_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__) - ) || source_vertex_index == destination_vertex_index - ) return __DEFAULT_BOOL__; - size_t src_index, dest_index; - _set_indexes_correctly(&src_index, source_vertex_index, &dest_index, destination_vertex_index); - bool already_added = Edge_exists(uwg->edges, src_index, dest_index); - if (anyThrows( - 1, - UndirectedWeightedGraph2_already_has_edge("UndirectedWeightedGraph2_add_Edge", already_added, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - - if (uwg->edges == __DEFAULT_PTR__) { - uwg->edges = Edge_create(src_index, dest_index, weight); - return __NOT_DEFAULT_BOOL__; - } else return Edge_add(uwg->edges, src_index, dest_index, weight); -} - -float UndirectedWeightedGraph2_get_weight(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index) { - if (anyThrows( - 1, - ExceptionHandler_is_null("UndirectedWeightedGraph2_get_weight", "Undirected Weighted Graph", uwg, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_FLOAT__; - size_t max_index = CircularDoublyLinkedList_size(uwg->vertices) - 1; - if (anyThrows( - 2, - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_get_weight", "Source Vertex", source_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_get_weight", "Destination Vertex", destination_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__) - ) || source_vertex_index == destination_vertex_index - ) return __DEFAULT_FLOAT__; - size_t src_index, dest_index; - _set_indexes_correctly(&src_index, source_vertex_index, &dest_index, destination_vertex_index); - Edge *edge = Edge_get_at(uwg->edges, src_index, dest_index); - return Edge_get_weight(edge); -} - -bool UndirectedWeightedGraph2_set_weight(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index, float new_weight) { - if (anyThrows( - 1, - ExceptionHandler_is_null("UndirectedWeightedGraph2_set_weight", "Undirected Weighted Graph", uwg, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - size_t max_index = CircularDoublyLinkedList_size(uwg->vertices) - 1; - if (anyThrows( - 2, - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_set_weight", "Source Vertex", source_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_set_weight", "Destination Vertex", destination_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__) - ) || source_vertex_index == destination_vertex_index - ) return __DEFAULT_BOOL__; - size_t src_index, dest_index; - _set_indexes_correctly(&src_index, source_vertex_index, &dest_index, destination_vertex_index); - Edge *edge = Edge_get_at(uwg->edges, src_index, dest_index); - return Edge_set_weight(edge, new_weight); -} - -bool UndirectedWeightedGraph2_is_empty(void *uwg) { - return CircularDoublyLinkedList_is_empty(((UndirectedWeightedGraph2 *) uwg)->vertices); -} - -bool UndirectedWeightedGraph2_remove_Vertex(UndirectedWeightedGraph2 *uwg, size_t vertex_index) { - if (anyThrows( - 1, - ExceptionHandler_is_null("UndirectedWeightedGraph2_remove_Vertex", "Undirected Weighted Graph", uwg, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - size_t max_index = CircularDoublyLinkedList_size(uwg->vertices) - 1; - if (anyThrows( - 1, - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_remove_Vertex", "Vertex index", vertex_index, max_index, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - if (Edge_remove_edges_with_index(uwg->edges, vertex_index)) return CircularDoublyLinkedList_remove_at(uwg->vertices, vertex_index); - return __NOT_DEFAULT_BOOL__; -} - -bool UndirectedWeightedGraph2_remove_Edge(UndirectedWeightedGraph2 *uwg, size_t source_vertex_index, size_t destination_vertex_index) { - if (anyThrows( - 1, - ExceptionHandler_is_null("UndirectedWeightedGraph2_remove_Edge", "Undirected Weighted Graph", uwg, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - size_t max_index = CircularDoublyLinkedList_size(uwg->vertices) - 1; - if (anyThrows( - 2, - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_remove_Edge", "Source Vertex", source_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_out_of_bounds("UndirectedWeightedGraph2_remove_Edge", "Destination Vertex", destination_vertex_index, max_index, __SUPPRESS_PRINT_ERROR__) - ) || source_vertex_index == destination_vertex_index - ) return __DEFAULT_BOOL__; - size_t src_index, dest_index; - _set_indexes_correctly(&src_index, source_vertex_index, &dest_index, destination_vertex_index); - return Edge_remove_at(uwg->edges, src_index, dest_index); -} diff --git a/main/UndirectedWeightedGraph2/test/tests/undirected_weighted_graph2.test.c b/main/UndirectedWeightedGraph2/test/tests/undirected_weighted_graph2.test.c deleted file mode 100644 index 6eafe04..0000000 --- a/main/UndirectedWeightedGraph2/test/tests/undirected_weighted_graph2.test.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "../../main/include/unity.h" -#include "../../main/include/undirected_weighted_graph2.h" - -void setUp(){} - -void tearDown(){} - -void test_1() { - TEST_MESSAGE("Please, write the tests."); - TEST_ASSERT_EQUAL(1, 1); -} - -int main(){ - UNITY_BEGIN(); - RUN_TEST(test_1); - // ... - return UNITY_END(); -} - diff --git a/resources/helpers/Edge/.info b/resources/helpers/Edge/.info deleted file mode 100644 index 99fbda5..0000000 --- a/resources/helpers/Edge/.info +++ /dev/null @@ -1 +0,0 @@ -pub_hp_ExceptionHandler diff --git a/resources/helpers/Edge/Makefile b/resources/helpers/Edge/Makefile deleted file mode 100644 index a649964..0000000 --- a/resources/helpers/Edge/Makefile +++ /dev/null @@ -1,84 +0,0 @@ -#helper -# Directories -MAIN = main -TEST = test -# Generics -BIN = bin -INCLUDE = include -LIB = lib -OBJ = obj -SRC = src -hp_FOLDER_0 = ../ExceptionHandler/$(MAIN) -#--ADD_FOLDER_NEW_hp - -# Names Definition -LIB_NAME = E -HELPER = edge -TEST_HELPER = edge.test -UNITY = ../../unity -DEPS = ../../scripts/dependencies -INSTALL = install.sh -hp_0 = exception_handler -#--ADD_NEW_hp -#hp1 - -# Compilation Flags -FLAGS = -O3 -Wall -pedantic -Warray-bounds -Werror -LIBS = -l$(LIB_NAME) -L $(MAIN)/$(LIB) - ---private-create_folders: - mkdir $(MAIN)/$(LIB) - mkdir $(MAIN)/$(OBJ) - mkdir $(TEST)/$(BIN) - ---private-get_external_lib: - cp $(hp_FOLDER_0)/$(SRC)/$(hp_0).c $(MAIN)/$(SRC)/ - cp $(hp_FOLDER_0)/$(INCLUDE)/$(hp_0).h $(MAIN)/$(INCLUDE)/ -#--ADD_GET_NEW_LIB - cp $(UNITY)/$(INCLUDE)/* $(MAIN)/$(INCLUDE)/ - cp $(UNITY)/$(SRC)/* $(MAIN)/$(SRC)/ - -pack: clean_all --private-create_folders --private-get_external_lib \ - $(MAIN)/$(OBJ)/$(HELPER).o \ - $(MAIN)/$(OBJ)/$(hp_0).o \ -#--ADD_TO_PACK - ar -rcs $(MAIN)/$(LIB)/lib$(LIB_NAME).a $(MAIN)/$(OBJ)/*.o - -compile_test: $(MAIN)/$(OBJ)/$(HELPER).o \ - $(MAIN)/$(OBJ)/unity.o \ - $(TEST)/$(BIN)/$(TEST_HELPER) \ - $(MAIN)/$(OBJ)/$(hp_0).o \ -#--ADD_TO_COMPILE_TEST - -run_tests: clean_all pack compile_test - $(TEST)/$(BIN)/$(TEST_HELPER) - make clean_all - -install_helper: - $(DEPS)/$(INSTALL) -h - -install: - $(DEPS)/$(INSTALL) -$(filter-out $@,$(MAKECMDGOALS)) - -clean_all: clean_libs clean_test clean_external - -clean_libs: - rm -rf $(MAIN)/$(OBJ) $(MAIN)/$(LIB) - -clean_test: - rm -rf $(TEST)/$(BIN) - -clean_external: - rm -rf $(MAIN)/$(SRC)/$(hp_0).c - rm -rf $(MAIN)/$(INCLUDE)/$(hp_0).h -#--ADD_TO_CLEAN - rm -rf $(MAIN)/$(SRC)/unity.c - rm -rf $(MAIN)/$(INCLUDE)/unity.h - rm -rf $(MAIN)/$(INCLUDE)/unity_internals.h - -$(MAIN)/$(OBJ)/%.o: $(MAIN)/$(SRC)/%.c $(MAIN)/$(INCLUDE)/%.h - gcc $(FLAGS) -c $< -I $(MAIN)/$(INCLUDE) -o $@ - -$(TEST)/$(BIN)/%: $(TEST)/tests/%.c - gcc $(FLAGS) $< $(MAIN)/$(OBJ)/*.o -I $(MAIN)/$(INCLUDE) -o $@ - diff --git a/resources/helpers/Edge/main/include/edge.h b/resources/helpers/Edge/main/include/edge.h deleted file mode 100644 index 62e7d42..0000000 --- a/resources/helpers/Edge/main/include/edge.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef EDGE_H -#define EDGE_H -#include "exception_handler.h" -//#--ADD_TO_INCLUDE - -#include -#include - -#ifdef __DEFAULT_FLOAT__ - #undef __DEFAULT_FLOAT__ -#endif -#ifdef __DEFAULT_SIZE_T__ - #undef __DEFAULT_SIZE_T__ -#endif -#ifdef __DEFAULT_BOOL__ - #undef __DEFAULT_BOOL__ -#endif -#ifdef __NOT_DEFAULT_BOOL__ - #undef __NOT_DEFAULT_BOOL__ -#endif -#ifdef __DEFAULT_PTR__ - #undef __DEFAULT_PTR__ -#endif -#ifdef __TYPE_COMPARE_FUNCTION_NAME__ - #undef __TYPE_COMPARE_FUNCTION_NAME__ -#endif -#ifdef __TYPE_COMPARE_FUNCTION_SIGNATURE__ - #undef __TYPE_COMPARE_FUNCTION_SIGNATURE__ -#endif -#ifdef __TYPE_PRINT_FUNCTION_NAME__ - #undef __TYPE_PRINT_FUNCTION_NAME__ -#endif -#ifdef __TYPE_PRINT_FUNCTION_SIGNATURE__ - #undef __TYPE_PRINT_FUNCTION_SIGNATURE__ -#endif - -#define __DEFAULT_FLOAT__ 0.0 -#define __DEFAULT_SIZE_T__ 0 -#define __DEFAULT_BOOL__ false -#define __NOT_DEFAULT_BOOL__ true -#define __DEFAULT_PTR__ NULL -#define __TYPE_COMPARE_FUNCTION_NAME__ type_compare_func -#define __TYPE_COMPARE_FUNCTION_SIGNATURE__ int (*__TYPE_COMPARE_FUNCTION_NAME__)(void *data1, void *data2) -#define __TYPE_PRINT_FUNCTION_NAME__ type_print_func -#define __TYPE_PRINT_FUNCTION_SIGNATURE__ void (*__TYPE_PRINT_FUNCTION_NAME__)(void *data) - -#define SIZE_OF_EDGE_TYPE size_of_edge_type - -extern const size_t size_of_edge_type; - -typedef struct _edge Edge; - -Edge *Edge_create(size_t src_vertex, size_t dest_vertex, float weight); - -bool Edge_add(Edge *edge, size_t src_vertex, size_t dest_vertex, float weight); - -Edge *Edge_get_at(Edge *edge, size_t src_index, size_t dest_index); - -float Edge_get_weight(Edge *edge); - -bool Edge_set_weight(Edge *edge, float new_weight); - -bool Edge_exists(Edge *edge, size_t src_index, size_t dest_index); - -bool Edge_remove(Edge *edge); - -bool Edge_remove_at(Edge *edge, size_t src_index, size_t dest_index); - -bool Edge_remove_edges_with_index(Edge *edge, size_t vertex_index); - -#endif diff --git a/resources/helpers/Edge/main/src/edge.c b/resources/helpers/Edge/main/src/edge.c deleted file mode 100644 index 0a28a5d..0000000 --- a/resources/helpers/Edge/main/src/edge.c +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include -//#--ADD_TO_INCLUDE -#include "../include/edge.h" - -typedef struct _edge { - size_t source_index; - size_t destination_index; - float weight; - struct _edge *next; - struct _edge *prev; -} Edge; - -const size_t size_of_edge_type = sizeof(Edge); - -Edge *Edge_create(size_t src_index, size_t dest_index, float weight) { - if (anyThrows( - 2, - ExceptionHandler_is_non_positive("Edge_create", "Source Index", src_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_create", "Destination Index", dest_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_PTR__; - Edge *edge = (Edge *) calloc(1, size_of_edge_type); - edge->source_index = src_index; - edge->destination_index = dest_index; - edge->weight = weight; - edge->next = __DEFAULT_PTR__; - edge->prev = __DEFAULT_PTR__; - return edge; -} - -bool Edge_add(Edge *edge, size_t src_index, size_t dest_index, float weight) { - if (anyThrows( - 3, - ExceptionHandler_is_null("Edge_add", "Edge", edge, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_add", "Source Index", src_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_add", "Destination Index", dest_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - Edge *next = Edge_create(src_index, dest_index, weight); - next->prev = edge; - Edge *temp_edge = edge; - while (temp_edge->next != __DEFAULT_PTR__) { - temp_edge = temp_edge->next; - } - temp_edge->next = next; - return __NOT_DEFAULT_BOOL__; -} - -Edge *Edge_get_at(Edge *edge, size_t src_index, size_t dest_index) { - if (anyThrows( - 3, - ExceptionHandler_is_null("Edge_get_at", "Edge", edge, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_get_at", "Source Index", src_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_get_at", "Destination Index", dest_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_PTR__; - Edge *temp_edge = edge; - while (temp_edge != __DEFAULT_PTR__) { - if (temp_edge->source_index == src_index && temp_edge->destination_index == dest_index) { - return temp_edge; - } - temp_edge = temp_edge->next; - } - return __DEFAULT_PTR__; -} - -float Edge_get_weight(Edge *edge) { - if (anyThrows( - 1, - ExceptionHandler_is_null("Edge_get_weight", "Edge", edge, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_FLOAT__; - return edge->weight; -} - -bool Edge_set_weight(Edge *edge, float new_weight) { - if (anyThrows( - 1, - ExceptionHandler_is_null("Edge_set_weight", "Edge", edge, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - edge->weight = new_weight; - return edge->weight == new_weight; -} - -bool Edge_exists(Edge *edge, size_t src_index, size_t dest_index) { - if (anyThrows( - 3, - ExceptionHandler_is_null("Edge_exists", "Edge", edge, __NOT_DEFAULT_BOOL__), - ExceptionHandler_is_non_positive("Edge_exists", "Source Index", src_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_exists", "Destination Index", dest_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - Edge *temp_edge = edge; - while (temp_edge != __DEFAULT_PTR__) { - if (temp_edge->source_index == src_index && temp_edge->destination_index == dest_index) { - return __NOT_DEFAULT_BOOL__; - } - temp_edge = temp_edge->next; - } - return __DEFAULT_BOOL__; -} - -bool Edge_remove(Edge *edge) { - if (anyThrows( - 1, - ExceptionHandler_is_null("Edge_remove", "Edge", edge, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - if (edge->prev != __DEFAULT_PTR__) edge->prev->next = edge->next; - if (edge->next != __DEFAULT_PTR__) edge->next->prev = edge->prev; - free(edge); - return __NOT_DEFAULT_BOOL__; -} - -bool Edge_remove_at(Edge *edge, size_t src_index, size_t dest_index) { - if (anyThrows( - 3, - ExceptionHandler_is_null("Edge_remove_at", "Edge", edge, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_remove_at", "Source Index", src_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_remove_at", "Destination Index", dest_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - Edge *edge_to_remove = Edge_get_at(edge, src_index, dest_index); - return Edge_remove(edge_to_remove); -} - -bool Edge_remove_edges_with_index(Edge *edge, size_t vertex_index) { - if (anyThrows( - 2, - ExceptionHandler_is_null("Edge_remove_edges_with_index", "Edge", edge, __SUPPRESS_PRINT_ERROR__), - ExceptionHandler_is_non_positive("Edge_remove_edges_with_index", "Vertex index", vertex_index, __NOT_DEFAULT_BOOL__, __SUPPRESS_PRINT_ERROR__) - ) - ) return __DEFAULT_BOOL__; - Edge *temp_edge = edge; - while (temp_edge != __DEFAULT_BOOL__) { - if (temp_edge->source_index == vertex_index || temp_edge->destination_index == vertex_index) { - if (!Edge_remove(temp_edge)) return __DEFAULT_BOOL__; - } - temp_edge = temp_edge->next; - } - return __NOT_DEFAULT_BOOL__; -} diff --git a/resources/helpers/Edge/test/tests/edge.test.c b/resources/helpers/Edge/test/tests/edge.test.c deleted file mode 100644 index 30fcbf6..0000000 --- a/resources/helpers/Edge/test/tests/edge.test.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "../../main/include/unity.h" -#include "../../main/include/edge.h" - -void setUp(){} - -void tearDown(){} - -void test_1() { - TEST_MESSAGE("Please, write the tests."); - TEST_ASSERT_EQUAL(1, 1); -} - -int main(){ - UNITY_BEGIN(); - RUN_TEST(test_1); - // ... - return UNITY_END(); -} - diff --git a/resources/scripts/dependencies/install_ds.sh b/resources/scripts/dependencies/install_ds.sh index 841902c..4c03688 100755 --- a/resources/scripts/dependencies/install_ds.sh +++ b/resources/scripts/dependencies/install_ds.sh @@ -269,7 +269,6 @@ ${PURPLE}7 )${WHITE} Static Queue ${PURPLE}8 )${WHITE} Dynamic Queue ${PURPLE}9 )${WHITE} Matrix ${PURPLE}10)${WHITE} Undirected Weighted Graph 1 (Adjacency Matrix) -${PURPLE}11)${WHITE} Undirected Weighted Graph 2 ${NO_COLOR}" #--DS read -r SELECTION @@ -285,7 +284,6 @@ case ${SELECTION} in 8 ) DEPENDENCY="DynamicQueue";; 9 ) DEPENDENCY="Matrix";; 10 ) DEPENDENCY="UndirectedWeightedGraph1";; - 11 ) DEPENDENCY="UndirectedWeightedGraph2";; #--ADD_NEW_OPT * ) echo "${YELLOW}Invalid selection: ${RED}${SELECTION}.${NO_COLOR}" diff --git a/resources/scripts/dependencies/install_helper.sh b/resources/scripts/dependencies/install_helper.sh index 58a3c31..1a01745 100755 --- a/resources/scripts/dependencies/install_helper.sh +++ b/resources/scripts/dependencies/install_helper.sh @@ -203,7 +203,6 @@ echo "${CYAN}Select a new dependency to add:${WHITE} ${PURPLE}1 )${WHITE} Exception Handler ${PURPLE}2 )${WHITE} Node ${PURPLE}3 )${WHITE} Vertex -${PURPLE}4 )${WHITE} Edge ${NO_COLOR}" #--H read -r SELECTION @@ -212,7 +211,6 @@ case ${SELECTION} in 1 ) DEPENDENCY="ExceptionHandler";; 2 ) DEPENDENCY="Node";; 3 ) DEPENDENCY="Vertex";; - 4 ) DEPENDENCY="Edge";; #--ADD_NEW_HELPER_OPT * ) echo "${YELLOW}Invalid selection: ${RED}${SELECTION}.${NO_COLOR}" diff --git a/resources/scripts/test/ci-test.sh b/resources/scripts/test/ci-test.sh index 8a831df..69b4693 100755 --- a/resources/scripts/test/ci-test.sh +++ b/resources/scripts/test/ci-test.sh @@ -6,7 +6,6 @@ HELPERS=( ExceptionHandler Node Vertex -Edge ) #--H DS=( @@ -20,7 +19,6 @@ StaticQueue DynamicQueue Matrix UndirectedWeightedGraph1 -UndirectedWeightedGraph2 ) #--DS function _title_case_to_snake_case() { diff --git a/resources/scripts/test/test_suite.sh b/resources/scripts/test/test_suite.sh index cd21e72..0bdd837 100755 --- a/resources/scripts/test/test_suite.sh +++ b/resources/scripts/test/test_suite.sh @@ -24,7 +24,6 @@ HELPERS=( ExceptionHandler Node Vertex -Edge ) #--H DS=( @@ -38,7 +37,6 @@ StaticQueue DynamicQueue Matrix UndirectedWeightedGraph1 -UndirectedWeightedGraph2 ) #--DS function _delta_T_in_ms() {