<commit_before><commit_msg>Add test for the residues C API<commit_after>// Force NDEBUG to be undefined
#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "chemfiles.h"
#include "helpers.h"

int main() {
    silent_crash_handlers();

    CHFL_RESIDUE* residue = chfl_residue("Foo", 56);
    assert(residue != NULL);

    char name[32] = {0};
    assert(!chfl_residue_name(residue, name, 32));
    assert(strcmp(name, "Foo") == 0);

    size_t resid = 0;
    assert(!chfl_residue_id(residue, &resid));
    assert(resid == 56);

    size_t size = 10;
    assert(!chfl_residue_atoms_count(residue, &size));
    assert(size == 0);

    assert(!chfl_residue_add_atom(residue, 0));
    assert(!chfl_residue_add_atom(residue, 1));
    assert(!chfl_residue_add_atom(residue, 2));

    assert(!chfl_residue_atoms_count(residue, &size));
    assert(size == 3);

    bool contains = false;
    assert(!chfl_residue_contains(residue, 1, &contains));
    assert(contains == true);
    assert(!chfl_residue_contains(residue, 16, &contains));
    assert(contains == false);

    CHFL_TOPOLOGY* topology = chfl_topology();

    assert(!chfl_topology_residues_count(topology, &size));
    assert(size == 0);

    assert(!chfl_topology_add_residue(topology, residue));
    assert(!chfl_residue_free(residue));

    assert(!chfl_topology_residues_count(topology, &size));
    assert(size == 1);

    residue = chfl_residue_from_topology(topology, 0);
    resid = 0;
    assert(!chfl_residue_id(residue, &resid));
    assert(resid == 56);
    assert(!chfl_residue_free(residue));

    residue = chfl_residue_from_topology(topology, 10);
    assert(residue == NULL);

    residue = chfl_residue_for_atom(topology, 2);
    resid = 0;
    assert(!chfl_residue_id(residue, &resid));
    assert(resid == 56);
    assert(!chfl_residue_free(residue));

    residue = chfl_residue_for_atom(topology, 10);
    assert(residue == NULL);

    assert(!chfl_topology_free(topology));

    return EXIT_SUCCESS;
}
{'fraction_non_alphanumeric': 0.14427860696517414, 'fraction_numerical': 0.017412935323383085, 'mean_word_length': 4.6016713091922, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2083091', 'n_tokens_mistral': 820, 'n_tokens_neox': 719, 'n_words': 126}