<commit_before>#include <stdio.h>
#include <stdlib.h>

#include <dlist.h>

#define QTD 10

void print_el(dlist_node *node) {
	printf("(");
	if (node != NULL) {
		if (node->prev != NULL) {
			printf("%d", *((int *) node->prev->data));
		} else {
			printf("NULL");
		}
		
		printf(", '%d', ", *((int *) node->data));
		
		if (node->next != NULL) {
			printf("%d", *((int *) node->next->data));
		} else {
			printf("NULL");
		}
	} else {
		printf("NULL");
	}
	printf(") ");
}

void print_list(dlist_root *list) {
	dlist_node *node = list->head;
	printf("List size: %d. Items: [", list->size);
	if (dlist_size(list) > 0) {
		do {
			print_el(node);
			node = node->next;
		} while (node != NULL);
	}
	printf("]\n");
}

int main() {
	dlist_root *a;
	int *num;
	
	a = (dlist_root *) malloc(sizeof(dlist_root));
	dlist_create(a, &free);
	
	printf("##### Test 1 - Insert in the head of the list (without current param)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i;
		dlist_insert_el_next(a, NULL, num);
	}
	print_list(a);
	
	printf("##### Test 2 - Insert in the middle of the list (with current param = head)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + QTD;
		dlist_insert_el_next(a, a->head, num);
	}
	print_list(a);
	
	printf("##### Test 3 - Insert in the tail of the list (with current param = tail)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + (QTD * 2);
		dlist_insert_el_next(a, a->tail, num);
	}
	print_list(a);
	
	printf("##### Test 4 - Insert in the tail of the list (without current param)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i;
		dlist_insert_el_prev(a, NULL, num);
	}
	print_list(a);
	
	printf("##### Test 5 - Insert in the middle of the list (with current param = tail)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + QTD;
		dlist_insert_el_prev(a, a->tail, num);
	}
	print_list(a);
	
	printf("##### Test 6 - Insert in the head of the list (with current param = head)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + (QTD * 2);
		dlist_insert_el_prev(a, a->head, num);
	}
	print_list(a);
	
	printf("##### Test 13 - Destroy list (call destroyfunc for every member)\n");
	dlist_destroy(a);
	print_list(a);
	
	free(a);<commit_msg>Add dlist tests.<commit_after>#include <stdio.h>
#include <stdlib.h>

#include <dlist.h>

#define QTD 10

void print_el(dlist_node *node) {
	printf("(");
	if (node != NULL) {
		if (node->prev != NULL) {
			printf("%d", *((int *) node->prev->data));
		} else {
			printf("NULL");
		}
		
		printf(", '%d', ", *((int *) node->data));
		
		if (node->next != NULL) {
			printf("%d", *((int *) node->next->data));
		} else {
			printf("NULL");
		}
	} else {
		printf("NULL");
	}
	printf(") ");
}

void print_list(dlist_root *list) {
	dlist_node *node = list->head;
	printf("List size: %d. Items: [", list->size);
	if (dlist_size(list) > 0) {
		do {
			print_el(node);
			node = node->next;
		} while (node != NULL);
	}
	printf("]\n");
}

int main() {
	dlist_root *a;
	int *num;
	
	a = (dlist_root *) malloc(sizeof(dlist_root));
	dlist_create(a, &free);
	
	printf("##### Test 1 - Insert in the head of the list (without current param)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i;
		dlist_insert_el_next(a, NULL, num);
	}
	print_list(a);
	
	printf("##### Test 2 - Insert in the middle of the list (with current param = head)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + QTD;
		dlist_insert_el_next(a, a->head, num);
	}
	print_list(a);
	
	printf("##### Test 3 - Insert in the tail of the list (with current param = tail)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + (QTD * 2);
		dlist_insert_el_next(a, a->tail, num);
	}
	print_list(a);
	
	printf("##### Test 4 - Insert in the tail of the list (without current param)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i;
		dlist_insert_el_prev(a, NULL, num);
	}
	print_list(a);
	
	printf("##### Test 5 - Insert in the middle of the list (with current param = tail)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + QTD;
		dlist_insert_el_prev(a, a->tail, num);
	}
	print_list(a);
	
	printf("##### Test 6 - Insert in the head of the list (with current param = head)\n");
	for (int i = 0; i < QTD; i++) {
		num = (int *) malloc(sizeof(int));
		*num = i + (QTD * 2);
		dlist_insert_el_prev(a, a->head, num);
	}
	print_list(a);
	
	printf("##### Test 7 - Remove from the head of the list\n");
	dlist_rem_el(a, a->head, (void *) &num);
	print_list(a);
	free(num);
	
	printf("##### Test 8 - Remove from the middle of the list\n");
	dlist_rem_el(a, a->head->next->next, (void *) &num);
	print_list(a);
	free(num);
	
	printf("##### Test 9 - Remove from the tail of the list\n");
	dlist_rem_el(a, a->tail, (void *) &num);
	print_list(a);
	free(num);
	
	printf("##### Test 10 - Destroy list (call destroyfunc for every member)\n");
	dlist_destroy(a);
	print_list(a);
	
	free(a);
{'fraction_non_alphanumeric': 0.21396959784491051, 'fraction_numerical': 0.007889166827015586, 'mean_word_length': 3.446535500427716, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6507977', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2056, 'n_words': 587}