<commit_before>#include "simpletest.h"
#include "foundation/container/iheap.h"
#include "foundation/util/iarraytypes.h"

SP_SUIT(iheap);

SP_CASE(iheap, iheapbuild) {
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    
    irelease(heap);
}

SP_CASE(iheap, iheapsize) {
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    
    SP_EQUAL(iheapsize(heap), 7);
    
    irelease(heap);
}

SP_CASE(iheap, iheapadd) {
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);

    int top = 7;
    iheapadd(heap, &top);
    SP_EQUAL(iarrayof(heap, int, 0), 7);
    
    irelease(heap);
}

SP_CASE(iheap, iheapadjust) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    
    irelease(heap);
}

SP_CASE(iheap, iheappeek) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    SP_EQUAL(iheappeekof(heap, int), 7);
    
    irelease(heap);
}

SP_CASE(iheap, iheappop) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    SP_EQUAL(iheappeekof(heap, int), 7);
    
    iheappop(heap);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    irelease(heap);
}

SP_CASE(iheap, iheapdelete) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    SP_EQUAL(iheappeekof(heap, int), 7);
    
    iheappop(heap);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    iheapdelete(heap, 3);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    iheapdelete(heap, 0);
    SP_EQUAL(iheappeekof(heap, int), 5);
    
    irelease(heap);
}

SP_CASE(iheap, iarraysortheap) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 4, 3, 2, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    /*
    irangearray(heap, int,
                ilog("%s%d%s", __key == 0 ? "arr=[" :"", __value, __key == 6 ? "]\n" :", ");
                );
     */
    
    iarraysortheap(heap, 2, 4);
    iarraysortheap(heap, 0, 6);
    
    SP_EQUAL(iarrayof(heap, int, 0), 0);
    SP_EQUAL(iarrayof(heap, int, 1), 1);
    SP_EQUAL(iarrayof(heap, int, 2), 2);
    SP_EQUAL(iarrayof(heap, int, 3), 3);
    SP_EQUAL(iarrayof(heap, int, 4), 4);
    SP_EQUAL(iarrayof(heap, int, 5), 5);
    SP_EQUAL(iarrayof(heap, int, 6), 6);
    
    irelease(heap);
}

SP_CASE(iheap, end) {
    SP_TRUE(1);
}

SP_CASE(iheap, mend) {
    imemoryglobalclear();
    
    SP_EQUAL(imemoryglobaluse(), _g_memory_in_use);
}<commit_msg>fix the test for heap<commit_after>#include "simpletest.h"
#include "foundation/container/iheap.h"
#include "foundation/util/iarraytypes.h"

SP_SUIT(iheap);

SP_CASE(iheap, iheapbuild) {
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    
    irelease(heap);
}

SP_CASE(iheap, iheapsize) {
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    
    SP_EQUAL(iheapsize(heap), 7);
    
    irelease(heap);
}

SP_CASE(iheap, iheapadd) {
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);

    int top = 7;
    iheapadd(heap, &top);
    SP_EQUAL(iarrayof(heap, int, 0), 7);
    
    irelease(heap);
}

SP_CASE(iheap, iheapadjust) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    
    irelease(heap);
}

SP_CASE(iheap, iheappeek) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    SP_EQUAL(iheappeekof(heap, int), 7);
    
    irelease(heap);
}

SP_CASE(iheap, iheappop) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    SP_EQUAL(iheappeekof(heap, int), 7);
    
    iheappop(heap);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    irelease(heap);
}

SP_CASE(iheap, iheapdelete) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 2, 3, 4, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    
    iheapbuild(heap);
    SP_EQUAL(iarrayof(heap, int, 0), 6);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    int top = 7;
    iarrayset(heap, 5, &top);
    iheapadjust(heap, 5);
    SP_EQUAL(iarrayof(heap, int, 0), 7)
    SP_EQUAL(iheappeekof(heap, int), 7);
    
    iheappop(heap);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    iheapdelete(heap, 3);
    SP_EQUAL(iheappeekof(heap, int), 6);
    
    iheapdelete(heap, 0);
    SP_EQUAL(iheappeekof(heap, int), 5);
    
    irelease(heap);
}

SP_CASE(iheap, iarraysortheap) {
    
    iheap *heap = iarraymakeint(10);
    int heap_values[] = {0, 1, 4, 3, 2, 5, 6};
    
    iarrayappend(heap, heap_values, icountof(heap_values));
    irangearray(heap, int,
                ilog("%s%d%s", __key == 0 ? "arr=[" :"", __value, __key == 6 ? "]\n" :", ");
                );
    
    iarraysortheap(heap, 2, 4);
    irangearray(heap, int,
                ilog("%s%d%s", __key == 0 ? "arr=[" :"", __value, __key == 6 ? "]\n" :", ");
                );
    iarraysortheap(heap, 0, 6);
    irangearray(heap, int,
                ilog("%s%d%s", __key == 0 ? "arr=[" :"", __value, __key == 6 ? "]\n" :", ");
                );
    
    SP_EQUAL(iarrayof(heap, int, 0), 0);
    SP_EQUAL(iarrayof(heap, int, 1), 1);
    SP_EQUAL(iarrayof(heap, int, 2), 2);
    SP_EQUAL(iarrayof(heap, int, 3), 3);
    SP_EQUAL(iarrayof(heap, int, 4), 4);
    SP_EQUAL(iarrayof(heap, int, 5), 5);
    SP_EQUAL(iarrayof(heap, int, 6), 6);
    
    irelease(heap);
}

SP_CASE(iheap, end) {
    SP_TRUE(1);
}

SP_CASE(iheap, mend) {
    imemoryglobalclear();
    
    SP_EQUAL(imemoryglobaluse(), _g_memory_in_use);
}

{'fraction_non_alphanumeric': 0.16603415559772297, 'fraction_numerical': 0.03439278937381404, 'mean_word_length': 2.9424964936886395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5540405', 'n_tokens_mistral': 3764, 'n_tokens_neox': 3494, 'n_words': 690}