<commit_before>
#include <structures/hash_table.h>

#include "test.h"

int main(int argc, char **argv)
{
    int i;
    struct bsal_hash_table table;
    int key_size;
    int value_size;
    uint64_t buckets;
    uint64_t key;

    BEGIN_TESTS();

    {
        buckets = 1048576;
        key = 1234;
        key_size = sizeof(key);
        value_size = 48;

        bsal_hash_table_init(&table, buckets, key_size, value_size);

        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);
        TEST_POINTER_NOT_EQUALS(bsal_hash_table_add(&table, &key), NULL);

        bsal_hash_table_delete(&table, &key);
        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);

        bsal_hash_table_destroy(&table);
    }

    {
        buckets = 4048;
        key = 1234;
        key_size = sizeof(key);
        value_size = 48;

        bsal_hash_table_init(&table, buckets, key_size, value_size);

        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);

        for (i = 0; i < 20; i++) {
            key = i;
            TEST_POINTER_NOT_EQUALS(bsal_hash_table_add(&table, &key), NULL);
        }

        bsal_hash_table_destroy(&table);
    }

    {
        /*printf("TEST OMEGA\n");*/

        buckets = 4041;
        key = 1234;
        key_size = sizeof(key);
        value_size = 48;

        bsal_hash_table_init(&table, buckets, key_size, value_size);

        /* init will allocate at least @buckets buckets */
        buckets = bsal_hash_table_buckets(&table);

        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);

        for (i = 0; i < buckets; i++) {
            key = i;

            TEST_INT_EQUALS(bsal_hash_table_elements(&table), i);
            /*printf("before adding %i\n", i);*/
            TEST_POINTER_NOT_EQUALS(bsal_hash_table_add(&table, &key), NULL);
            /*printf("elements after adding %i : %i\n", i,
                            bsal_hash_table_elements(&table)); */
            TEST_INT_EQUALS(bsal_hash_table_elements(&table), i + 1);
        }

        key = 9999;
        /* try to add something to a full table */
        TEST_POINTER_EQUALS(bsal_hash_table_add(&table, &key), NULL);
        TEST_INT_EQUALS(bsal_hash_table_elements(&table), buckets);

        bsal_hash_table_destroy(&table);
    }



    END_TESTS();

    return 0;
}<commit_msg>add test for get() in hash table<commit_after>
#include <structures/hash_table.h>

#include "test.h"

int main(int argc, char **argv)
{
    int i;
    struct bsal_hash_table table;
    int key_size;
    int value_size;
    uint64_t buckets;
    uint64_t key;

    BEGIN_TESTS();

    {
        buckets = 1048576;
        key = 1234;
        key_size = sizeof(key);
        value_size = 48;

        bsal_hash_table_init(&table, buckets, key_size, value_size);

        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);
        TEST_POINTER_NOT_EQUALS(bsal_hash_table_add(&table, &key), NULL);

        bsal_hash_table_delete(&table, &key);
        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);

        bsal_hash_table_destroy(&table);
    }

    {
        buckets = 4048;
        key = 1234;
        key_size = sizeof(key);
        value_size = 48;

        bsal_hash_table_init(&table, buckets, key_size, value_size);

        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);

        for (i = 0; i < 20; i++) {
            key = i;
            TEST_POINTER_NOT_EQUALS(bsal_hash_table_add(&table, &key), NULL);
        }

        bsal_hash_table_destroy(&table);
    }

    {
        /*printf("TEST OMEGA\n");*/

        buckets = 4041;
        key = 1234;
        key_size = sizeof(key);
        value_size = 48;

        bsal_hash_table_init(&table, buckets, key_size, value_size);

        /* init will allocate at least @buckets buckets */
        buckets = bsal_hash_table_buckets(&table);

        TEST_POINTER_EQUALS(bsal_hash_table_get(&table, &key), NULL);

        for (i = 0; i < buckets; i++) {
            key = i;

            TEST_INT_EQUALS(bsal_hash_table_elements(&table), i);
            /*printf("before adding %i\n", i);*/
            TEST_POINTER_NOT_EQUALS(bsal_hash_table_add(&table, &key), NULL);
            /*printf("elements after adding %i : %i\n", i,
                            bsal_hash_table_elements(&table)); */
            TEST_INT_EQUALS(bsal_hash_table_elements(&table), i + 1);

            TEST_POINTER_NOT_EQUALS(bsal_hash_table_get(&table, &key), NULL);
        }

        key = 9999;
        /* try to add something to a full table */
        TEST_POINTER_EQUALS(bsal_hash_table_add(&table, &key), NULL);
        TEST_INT_EQUALS(bsal_hash_table_elements(&table), buckets);

        bsal_hash_table_destroy(&table);
    }



    END_TESTS();

    return 0;
}
{'fraction_non_alphanumeric': 0.11967418546365914, 'fraction_numerical': 0.019632414369256473, 'mean_word_length': 2.408540925266904, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '1646498', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1641, 'n_words': 303}