<commit_before>#include <stdio.h> /* fopen, puts */
#include <stdlib.h> /* exit */
#include <string.h> /* strcmp */
#include <assert.h> /* assert */

#include "../../src/data/pvector.h"

int main(void){
    int i;
    struct ic_pvector *arr = ic_pvector_new(5);

    assert(arr);
    assert(arr->used == 0);
    assert(arr->cap == 5);

    /* check that fetching out of range is an error */
    assert(ic_pvector_get(arr, 0) == 0);

    /* a pvector should grow on append
     * since our starting size is 5 the next growth should be
     * to 10
     */
    for(i=0; i<10; ++i){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 10);
    assert(arr->cap == 10);

    /* we can also artifically grow a pvector */
    assert(ic_pvector_ensure(arr, 20) == 0);

    /* this should not change used */
    assert(arr->used == 10);
    /* but should increase cap */
    assert(arr->cap == 20);


    /* also test default growth pattern
     * if we do not set an initial size then growth is based on
     * PVECTOR_DEFAULT_GROWTH
     */
    arr = ic_pvector_new(0);

    assert(arr);
    assert(arr->used == 0);
    assert(arr->cap == 8);

    /* push over current 0 capacity
     * this will cause our first resize
     */
    for( i=0; i<8; ++i ){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 8);
    assert(arr->cap == 8);

    /* push over current 8 capacity */
    for( i=8; i<12; ++i ){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 12);
    assert(arr->cap == 16);

    /* push over current 16 capacity */
    for( i=12; i<18; ++i ){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 18);
    assert(arr->cap == 32);

    return 0;
}<commit_msg>increasing pvector test coverage<commit_after>#include <stdio.h> /* fopen, puts */
#include <stdlib.h> /* exit */
#include <string.h> /* strcmp */
#include <assert.h> /* assert */

#include "../../src/data/pvector.h"

void normal(void){
    int i;
    struct ic_pvector *arr = ic_pvector_new(5);

    assert(arr);
    assert(arr->used == 0);
    assert(arr->cap == 5);

    /* check that fetching out of range is an error */
    assert(ic_pvector_get(arr, 0) == 0);

    /* a pvector should grow on append
     * since our starting size is 5 the next growth should be
     * to 10
     */
    for(i=0; i<10; ++i){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 10);
    assert(arr->cap == 10);

    /* we can also artifically grow a pvector */
    assert(ic_pvector_ensure(arr, 20) == 0);

    /* this should not change used */
    assert(arr->used == 10);
    /* but should increase cap */
    assert(arr->cap == 20);


    /* also test default growth pattern
     * if we do not set an initial size then growth is based on
     * PVECTOR_DEFAULT_GROWTH
     */
    arr = ic_pvector_new(0);

    assert(arr);
    assert(arr->used == 0);
    assert(arr->cap == 8);

    /* ensure to same or less size should do nothing */
    assert( 0 == ic_pvector_ensure(arr, 8) );
    assert(arr->used == 0);
    assert(arr->cap == 8);
    assert( 0 == ic_pvector_ensure(arr, 4) );
    assert(arr->used == 0);
    assert(arr->cap == 8);

    /* push over current 0 capacity
     * this will cause our first resize
     */
    for( i=0; i<8; ++i ){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 8);
    assert(arr->cap == 8);

    /* push over current 8 capacity */
    for( i=8; i<12; ++i ){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 12);
    assert(arr->cap == 16);

    /* push over current 16 capacity */
    for( i=12; i<18; ++i ){
        assert(ic_pvector_append(arr, arr) == i);
        assert(ic_pvector_get(arr, i) == arr);
    }

    assert(arr->used == 18);
    assert(arr->cap == 32);
}

void abnormal(void){
    /* test null pvector args */
    assert( 1 == ic_pvector_init(0, 0) );
    assert( 0 == ic_pvector_get(0, 0) );
    assert( -1 == ic_pvector_append(0, 0) );
    assert( 1 == ic_pvector_ensure(0, 0) );
    assert( 0 == ic_pvector_length(0) );
}

int main(void){
    normal();
    abnormal();

    return 0;
}
{'fraction_non_alphanumeric': 0.167989417989418, 'fraction_numerical': 0.026455026455026454, 'mean_word_length': 2.447568389057751, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 43, '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': '7019977', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1573, 'n_words': 429}