<commit_before>#include <check.h>
#include <time.h>
#include "../src/treenode.h"

// DECLARE VARS
TreeBase tree_base_int_1, *ptr_tree_base_int_1;
TreeNode *ptr_tree_node;
int *int_arr_ptr;
int arr_size = 40;
bool isValid;

void setup_x(void) {
    int_arr_ptr = malloc(arr_size * (sizeof(int)));
    ptr_tree_base_int_1 = new_base(comp_ints, clean_ints, print_ints);
    if(!ptr_tree_base_int_1 || !int_arr_ptr) {
        printf("Error allocating memory in test Setup\n");
        fflush(stdout);
        assert(NULL);
    }
    srand(time(NULL));
    for (int i = 0; i < arr_size; ++i) {
        int r = (rand() % 20000) - 10000;
        *(int_arr_ptr+i) = r;
    }
}

void teardown_x(void){
    if (ptr_tree_base_int_1){
        isValid = freeTree(ptr_tree_base_int_1);
        ck_assert_int_eq(isValid, true);
        free(ptr_tree_base_int_1);
        ptr_tree_base_int_1 = NULL;
    }
    if(int_arr_ptr){
        free(int_arr_ptr);
        int_arr_ptr = NULL;
    }
}

START_TEST(test_CHECK) {
        ck_assert_int_eq(true, 1);
        ck_assert_int_eq(false, 0);
        ck_assert_int_eq(5, 5);
} END_TEST

START_TEST(test_COMP_INTS) {
        int a,b,c;
        a = b = c = -234;
        ck_assert_int_eq(comp_ints(&a,&b), 0);
        ck_assert_int_eq(comp_ints(&a,&c), 0);
        ck_assert_int_eq(comp_ints(&c,&b), 0);
        b = 234;
        c = 345;
        ck_assert_int_eq(comp_ints(&a,&b), -1);
        ck_assert_int_eq(comp_ints(&a,&c), -1);
        ck_assert_int_eq(comp_ints(&c,&b), 1);
        ck_assert_int_eq(comp_ints(&b,&a), 1);
        ck_assert_int_eq(comp_ints(&c,&a), 1);
        ck_assert_int_eq(comp_ints(&b,&c), -1);
        ck_assert_int_eq(comp_ints(&a,&a), 0);
        ck_assert_int_eq(comp_ints(&b,&b), 0);
        ck_assert_int_eq(comp_ints(&c,&c), 0);
    } END_TEST

START_TEST(test_CLEAN_INTS) {
        int *a = malloc(sizeof(int));
        // check if memory was allocated
        if(a) {
            *a = 234;
            ck_assert_int_eq(*a, 234);
            clean_ints(a);
            a = NULL;
            if(a) {
                ck_abort_msg("FAILED freeing pointer\n");
            }
        }
    } END_TEST

START_TEST(test_PRINT_INTS) {
        char *a = malloc(6*sizeof(char));
        // check if memory was allocated
        if(a) {
            a = "abcde\0";
            printf("!!!Next line has to be:\"abcde\"\n");
            fflush(stdout);
            print_strs(a);
            clean_strs(a);
        }
    } END_TEST

START_TEST(test_COMP_STRS) {
        char *a,*b,*c;
        a = b = c = "abyrvalg\0";
        ck_assert_int_eq(comp_strs(&a,&b), 0);
        ck_assert_int_eq(comp_strs(&a,&c), 0);
        ck_assert_int_eq(comp_strs(&c,&b), 0);
        *b = "masdf\0";
        *c = "z\0";
        ck_assert_int_eq(comp_strs(&a,&b), -1);
        ck_assert_int_eq(comp_strs(&a,&c), -1);
        ck_assert_int_eq(comp_strs(&c,&b), 1);
        ck_assert_int_eq(comp_strs(&b,&a), 1);
        ck_assert_int_eq(comp_strs(&c,&a), 1);
        ck_assert_int_eq(comp_strs(&b,&c), -1);
        ck_assert_int_eq(comp_strs(&a,&a), 0);
        ck_assert_int_eq(comp_strs(&b,&b), 0);
        ck_assert_int_eq(comp_strs(&c,&c), 0);
    } END_TEST

START_TEST(test_CLEAN_STRS) {
        char *a = malloc(4*sizeof(char));
        // check if memory was allocated
        if(a) {
            a = "asd\0";
            clean_strs(a);<commit_msg>[FIX]     check_test.c: In function ‘test_COMP_STRS’:     check_test.c:97:12: error: assignment makes integer from pointer without a cast [-Werror]     check_test.c:98:12: error: assignment makes integer from pointer without a cast [-Werror]<commit_after>#include <check.h>
#include <time.h>
#include "../src/treenode.h"

// DECLARE VARS
TreeBase tree_base_int_1, *ptr_tree_base_int_1;
TreeNode *ptr_tree_node;
int *int_arr_ptr;
int arr_size = 40;
bool isValid;

void setup_x(void) {
    int_arr_ptr = malloc(arr_size * (sizeof(int)));
    ptr_tree_base_int_1 = new_base(comp_ints, clean_ints, print_ints);
    if(!ptr_tree_base_int_1 || !int_arr_ptr) {
        printf("Error allocating memory in test Setup\n");
        fflush(stdout);
        assert(NULL);
    }
    srand(time(NULL));
    for (int i = 0; i < arr_size; ++i) {
        int r = (rand() % 20000) - 10000;
        *(int_arr_ptr+i) = r;
    }
}

void teardown_x(void){
    if (ptr_tree_base_int_1){
        isValid = freeTree(ptr_tree_base_int_1);
        ck_assert_int_eq(isValid, true);
        free(ptr_tree_base_int_1);
        ptr_tree_base_int_1 = NULL;
    }
    if(int_arr_ptr){
        free(int_arr_ptr);
        int_arr_ptr = NULL;
    }
}

START_TEST(test_CHECK) {
        ck_assert_int_eq(true, 1);
        ck_assert_int_eq(false, 0);
        ck_assert_int_eq(5, 5);
} END_TEST

START_TEST(test_COMP_INTS) {
        int a,b,c;
        a = b = c = -234;
        ck_assert_int_eq(comp_ints(&a,&b), 0);
        ck_assert_int_eq(comp_ints(&a,&c), 0);
        ck_assert_int_eq(comp_ints(&c,&b), 0);
        b = 234;
        c = 345;
        ck_assert_int_eq(comp_ints(&a,&b), -1);
        ck_assert_int_eq(comp_ints(&a,&c), -1);
        ck_assert_int_eq(comp_ints(&c,&b), 1);
        ck_assert_int_eq(comp_ints(&b,&a), 1);
        ck_assert_int_eq(comp_ints(&c,&a), 1);
        ck_assert_int_eq(comp_ints(&b,&c), -1);
        ck_assert_int_eq(comp_ints(&a,&a), 0);
        ck_assert_int_eq(comp_ints(&b,&b), 0);
        ck_assert_int_eq(comp_ints(&c,&c), 0);
    } END_TEST

START_TEST(test_CLEAN_INTS) {
        int *a = malloc(sizeof(int));
        // check if memory was allocated
        if(a) {
            *a = 234;
            ck_assert_int_eq(*a, 234);
            clean_ints(a);
            a = NULL;
            if(a) {
                ck_abort_msg("FAILED freeing pointer\n");
            }
        }
    } END_TEST

START_TEST(test_PRINT_INTS) {
        char *a = malloc(6*sizeof(char));
        // check if memory was allocated
        if(a) {
            a = "abcde\0";
            printf("!!!Next line has to be:\"abcde\"\n");
            fflush(stdout);
            print_strs(a);
            clean_strs(a);
        }
    } END_TEST

START_TEST(test_COMP_STRS) {
        char *a,*b,*c;
        a = b = c = "abyrvalg\0";
        ck_assert_int_eq(comp_strs(&a,&b), 0);
        ck_assert_int_eq(comp_strs(&a,&c), 0);
        ck_assert_int_eq(comp_strs(&c,&b), 0);
        b = "masdf\0";
        c = "z\0";
        ck_assert_int_eq(comp_strs(&a,&b), -1);
        ck_assert_int_eq(comp_strs(&a,&c), -1);
        ck_assert_int_eq(comp_strs(&c,&b), 1);
        ck_assert_int_eq(comp_strs(&b,&a), 1);
        ck_assert_int_eq(comp_strs(&c,&a), 1);
        ck_assert_int_eq(comp_strs(&b,&c), -1);
        ck_assert_int_eq(comp_strs(&a,&a), 0);
        ck_assert_int_eq(comp_strs(&b,&b), 0);
        ck_assert_int_eq(comp_strs(&c,&c), 0);
    } END_TEST

START_TEST(test_CLEAN_STRS) {
        char *a = malloc(4*sizeof(char));
        // check if memory was allocated
        if(a) {
            a = "asd\0";
            clean_strs(a);
{'fraction_non_alphanumeric': 0.15218633895398687, 'fraction_numerical': 0.021434695627322094, 'mean_word_length': 2.43762278978389, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '613212', 'n_tokens_mistral': 2958, 'n_tokens_neox': 2766, 'n_words': 435}