<commit_before>#include "sput.h"
#include "dynar.h"

static void testNull(void)
{
    int err;
    int ignore;
    DaStruct da;

    sput_fail_if(daAppend(NULL, NULL, &ignore) != NULL, "daAppend(NULL, NULL, &ignore) != NULL");
    sput_fail_if(daAppend(NULL, NULL, NULL)    != NULL, "daAppend(NULL, NULL, NULL)    != NULL");
    sput_fail_if(daAppend(&da,  NULL, &ignore) != NULL, "daAppend(da,   NULL, &ignore) != NULL");
    sput_fail_if(daAppend(&da,  NULL, NULL)    != NULL, "daAppend(da,   NULL, NULL)    != NULL");

    sput_fail_if(daAppend(&da,  &err, NULL)    != NULL, "daAppend(da,   &err, NULL)    != NULL");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");

    sput_fail_if(daAppend(NULL, &err, &ignore) != NULL, "daAppend(NULL, &err, &ignore) != NULL");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");

    sput_fail_if(daAppend(NULL, &err, NULL)    != NULL, "daAppend(NULL, &err, NULL)    != NULL");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");
}

static void testAppend(void)
{
    int err;
    const char *src;
    const char *expect;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 3;
    desc.bytesPerElement = 1;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");

    src = "0";
    expect = "0";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr, "daAppend should return the address of the first element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 1) != 0, "daAppend should copy the element to the first position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 1, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 1, "daAppend should decrease the used counter");


    src = "1";
    expect = "01";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr + 1, "daAppend should return the address of the second element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 2) != 0, "daAppend should copy the element to the second position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 2, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 2, "daAppend should decrease the used counter");


    src = "2";
    expect = "012";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr + 2, "daAppend should return the address of the third element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 3) != 0, "daAppend should copy the element to the third position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 3, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 3, "daAppend should decrease the used counter");
}

static void testRealloc(void)
{
    int err;
    void *firstAddrCmp;
    void *LastAddrCmp;
    void *freeAddrCmp;
    const char *src;
    const char *expect;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 1;
    desc.bytesPerElement = 1;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");


    src = "0";
    expect = "0";
    sput_fail_if(daAppend(da, &err, src) != (char *)da->firstAddr, "daAppend should return the address of the appended element");
    sput_fail_if(err != DA_OK, "err != DA_OK");




    firstAddrCmp = da->firstAddr;
    LastAddrCmp = da->lastAddr;
    freeAddrCmp = da->freeAddr;
    src = "1";
    expect = "01";
    sput_fail_if(daAppend(da, &err, src) != (char *)da->firstAddr + 1, "daAppend should return the address of the appended element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 2) != 0, "daAppend should copy the element to the second position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 2, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 2, "daAppend should decrease the used counter");
    sput_fail_if(da->firstAddr == firstAddrCmp, "daAppend should update the firstAddr pointer");
    sput_fail_if(da->lastAddr == LastAddrCmp, "daAppend should update the lastAddr pointer");
    sput_fail_if(da->freeAddr == freeAddrCmp, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->max != 2, "daAppend should double the maximum amount of elements");




    firstAddrCmp = da->firstAddr;
    LastAddrCmp = da->lastAddr;
    freeAddrCmp = da->freeAddr;
    src = "2";
    expect = "012";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr + 2, "daAppend should append the third element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 3) != 0, "daAppend should copy the element to the third position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 3, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 3, "daAppend should decrease the used counter");
    sput_fail_if(da->firstAddr == firstAddrCmp, "daAppend should update the firstAddr pointer");
    sput_fail_if(da->lastAddr == LastAddrCmp, "daAppend should update the lastAddr pointer");
    sput_fail_if(da->freeAddr == freeAddrCmp, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->max != 4, "daAppend should double the maximum amount of elements");
}

static void testBytesLimit(void)
{
    int err;
    char *src;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 1;
    desc.bytesPerElement = DA_MAX_BYTES;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");

    src = malloc(DA_MAX_BYTES);
    sput_fail_if(src == NULL, "Unable to allocate space for the input");<commit_msg>Fixed wrong test description. Used counter should be increased instead of decreased.<commit_after>#include "sput.h"
#include "dynar.h"

static void testNull(void)
{
    int err;
    int ignore;
    DaStruct da;

    sput_fail_if(daAppend(NULL, NULL, &ignore) != NULL, "daAppend(NULL, NULL, &ignore) != NULL");
    sput_fail_if(daAppend(NULL, NULL, NULL)    != NULL, "daAppend(NULL, NULL, NULL)    != NULL");
    sput_fail_if(daAppend(&da,  NULL, &ignore) != NULL, "daAppend(da,   NULL, &ignore) != NULL");
    sput_fail_if(daAppend(&da,  NULL, NULL)    != NULL, "daAppend(da,   NULL, NULL)    != NULL");

    sput_fail_if(daAppend(&da,  &err, NULL)    != NULL, "daAppend(da,   &err, NULL)    != NULL");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");

    sput_fail_if(daAppend(NULL, &err, &ignore) != NULL, "daAppend(NULL, &err, &ignore) != NULL");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");

    sput_fail_if(daAppend(NULL, &err, NULL)    != NULL, "daAppend(NULL, &err, NULL)    != NULL");
    sput_fail_if(err != (DA_PARAM_ERR | DA_PARAM_NULL), "err != (DA_PARAM_ERR | DA_PARAM_NULL)");
}

static void testAppend(void)
{
    int err;
    const char *src;
    const char *expect;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 3;
    desc.bytesPerElement = 1;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");

    src = "0";
    expect = "0";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr, "daAppend should return the address of the first element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 1) != 0, "daAppend should copy the element to the first position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 1, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 1, "daAppend should increase the used counter");


    src = "1";
    expect = "01";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr + 1, "daAppend should return the address of the second element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 2) != 0, "daAppend should copy the element to the second position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 2, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 2, "daAppend should increase the used counter");


    src = "2";
    expect = "012";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr + 2, "daAppend should return the address of the third element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 3) != 0, "daAppend should copy the element to the third position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 3, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 3, "daAppend should increase the used counter");
}

static void testRealloc(void)
{
    int err;
    void *firstAddrCmp;
    void *LastAddrCmp;
    void *freeAddrCmp;
    const char *src;
    const char *expect;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 1;
    desc.bytesPerElement = 1;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");


    src = "0";
    expect = "0";
    sput_fail_if(daAppend(da, &err, src) != (char *)da->firstAddr, "daAppend should return the address of the appended element");
    sput_fail_if(err != DA_OK, "err != DA_OK");




    firstAddrCmp = da->firstAddr;
    LastAddrCmp = da->lastAddr;
    freeAddrCmp = da->freeAddr;
    src = "1";
    expect = "01";
    sput_fail_if(daAppend(da, &err, src) != (char *)da->firstAddr + 1, "daAppend should return the address of the appended element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 2) != 0, "daAppend should copy the element to the second position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 2, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 2, "daAppend should increase the used counter");
    sput_fail_if(da->firstAddr == firstAddrCmp, "daAppend should update the firstAddr pointer");
    sput_fail_if(da->lastAddr == LastAddrCmp, "daAppend should update the lastAddr pointer");
    sput_fail_if(da->freeAddr == freeAddrCmp, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->max != 2, "daAppend should double the maximum amount of elements");




    firstAddrCmp = da->firstAddr;
    LastAddrCmp = da->lastAddr;
    freeAddrCmp = da->freeAddr;
    src = "2";
    expect = "012";
    sput_fail_if(daAppend(da, &err, src) !=  (char *)da->firstAddr + 2, "daAppend should append the third element");
    sput_fail_if(err != DA_OK, "err != DA_OK");
    sput_fail_if(memcmp(da->firstAddr, expect, 3) != 0, "daAppend should copy the element to the third position");
    sput_fail_if(da->freeAddr != (char *)da->firstAddr + 3, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->used != 3, "daAppend should increase the used counter");
    sput_fail_if(da->firstAddr == firstAddrCmp, "daAppend should update the firstAddr pointer");
    sput_fail_if(da->lastAddr == LastAddrCmp, "daAppend should update the lastAddr pointer");
    sput_fail_if(da->freeAddr == freeAddrCmp, "daAppend should update the freeAddr pointer");
    sput_fail_if(da->max != 4, "daAppend should double the maximum amount of elements");
}

static void testBytesLimit(void)
{
    int err;
    char *src;
    DaDesc desc;
    DaStruct *da;

    desc.elements = 1;
    desc.bytesPerElement = DA_MAX_BYTES;
    da = daCreate(&desc, &err);
    sput_fail_if(da == NULL, "Unable to create dynamic array.");

    src = malloc(DA_MAX_BYTES);
    sput_fail_if(src == NULL, "Unable to allocate space for the input");
{'fraction_non_alphanumeric': 0.14422831903508027, 'fraction_numerical': 0.008324131487301453, 'mean_word_length': 3.993214588634436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 83, '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': '761579', 'n_tokens_mistral': 4170, 'n_tokens_neox': 4048, 'n_words': 1120}