<commit_before>#include <stdlib.h> /* free */
#include <stdio.h> /* printf */

/* don't included libcheck when I am included as part of test_main.c */
#ifndef PLOT_TEST_MAIN
#define PLOT_TEST_MAIN
#include <check.h>
#include "test.h"
#endif

#include "../src/value.h"
#include "../src/hash.h"

START_TEST (test_hash){
    const plot_symbol a = (plot_symbol){"a", 2, 2};
    const plot_symbol b = (plot_symbol){"b", 2, 2};
    const plot_symbol c = (plot_symbol){"c", 2, 2};

    plot_value value;
    plot_hash hash;
    hash.n_elems = 0;

    puts("\tTesting hash construction");
    fail_if( 0 == plot_init() );
    fail_if( 0 == (plot_hash_init(&hash)) );

    puts("\tTesting basic hash get and insert");
    fail_if( plot_hash_get(&hash, &b) );
    fail_unless( plot_hash_set(&hash, &b, &value) );
    fail_if( plot_hash_get(&hash, &b) != &value );
    fail_if( plot_hash_get(&hash, &a) );

    puts("\tTesting for correct key ordering");
    fail_unless( plot_hash_set(&hash, &a, &value) );
    fail_unless( plot_hash_set(&hash, &c, &value) );
    fail_if( strcmp(a.val, hash.head->key->val) );
    fail_if( strcmp(b.val, hash.head->next->key->val) );
    fail_if( strcmp(c.val, hash.head->next->next->key->val) );

    puts("\tTesting correct number of elements");
    fail_unless( hash.head->next->next->next == 0 );
    fail_unless( hash.n_elems == 3);

    puts("\tTesting mutation");
    fail_unless( plot_hash_set(&hash, &b, 0) );
    fail_unless( 0 == plot_hash_get(&hash, &b) );
    fail_unless( 3 == hash.n_elems );

    plot_hash_cleanup(&hash);<commit_msg>fixing silly unitialised refcount in test_hash<commit_after>#include <stdlib.h> /* free */
#include <stdio.h> /* printf */

/* don't included libcheck when I am included as part of test_main.c */
#ifndef PLOT_TEST_MAIN
#define PLOT_TEST_MAIN
#include <check.h>
#include "test.h"
#endif

#include "../src/value.h"
#include "../src/hash.h"

START_TEST (test_hash){
    const plot_symbol a = (plot_symbol){"a", 2, 2};
    const plot_symbol b = (plot_symbol){"b", 2, 2};
    const plot_symbol c = (plot_symbol){"c", 2, 2};

    plot_value value;
    plot_hash hash;
    hash.n_elems = 0;
    value.gc.refcount = 1;

    puts("\tTesting hash construction");
    fail_if( 0 == plot_init() );
    fail_if( 0 == (plot_hash_init(&hash)) );

    puts("\tTesting basic hash get and insert");
    fail_if( plot_hash_get(&hash, &b) );
    fail_unless( plot_hash_set(&hash, &b, &value) );
    fail_if( plot_hash_get(&hash, &b) != &value );
    fail_if( plot_hash_get(&hash, &a) );

    puts("\tTesting for correct key ordering");
    fail_unless( plot_hash_set(&hash, &a, &value) );
    fail_unless( plot_hash_set(&hash, &c, &value) );
    fail_if( strcmp(a.val, hash.head->key->val) );
    fail_if( strcmp(b.val, hash.head->next->key->val) );
    fail_if( strcmp(c.val, hash.head->next->next->key->val) );

    puts("\tTesting correct number of elements");
    fail_unless( hash.head->next->next->next == 0 );
    fail_unless( hash.n_elems == 3);

    puts("\tTesting mutation");
    fail_unless( plot_hash_set(&hash, &b, 0) );
    fail_unless( 0 == plot_hash_get(&hash, &b) );
    fail_unless( 3 == hash.n_elems );

    plot_hash_cleanup(&hash);
{'fraction_non_alphanumeric': 0.17779164067373673, 'fraction_numerical': 0.009045539613225203, 'mean_word_length': 3.709251101321586, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '7097997', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1182, 'n_words': 270}