<commit_before>//--------------------------------------------------------------------------
//
// Copyright (C) 2013 <NAME>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
//--------------------------------------------------------------------------

#include <tuna/kernel.h>

#include "fct.h"

// Many tests rely on having a known number of outliers
enum { noutliers = 5 };

FCT_BGN()
{
    FCT_QTEST_BGN(examine)
    {
        tuna_kernel k = {};

        // Testing initial behavior before any observations provided
        fct_chk_eq_int(noutliers, sizeof(k.outliers)/sizeof(k.outliers[0]));
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        for (int i = 0; i < noutliers; ++i) {
            fct_chk_eq_dbl(k.outliers[i], 0);
        }

        // Record observations 1, 3, 5, 0, 7, 9, 0 checking state after each

        tuna_kernel_obs(&k, 1); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 0);
        fct_chk_eq_dbl(k.outliers[3], 0);
        fct_chk_eq_dbl(k.outliers[4], 1);

        tuna_kernel_obs(&k, 3); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 0);
        fct_chk_eq_dbl(k.outliers[3], 1);
        fct_chk_eq_dbl(k.outliers[4], 3);

        tuna_kernel_obs(&k, 5); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 1);
        fct_chk_eq_dbl(k.outliers[3], 3);
        fct_chk_eq_dbl(k.outliers[4], 5);

        tuna_kernel_obs(&k, 0); // Ignored
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 1);
        fct_chk_eq_dbl(k.outliers[3], 3);
        fct_chk_eq_dbl(k.outliers[4], 5);

        tuna_kernel_obs(&k, 7); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 1);
        fct_chk_eq_dbl(k.outliers[2], 3);
        fct_chk_eq_dbl(k.outliers[3], 5);
        fct_chk_eq_dbl(k.outliers[4], 7);

        tuna_kernel_obs(&k, 9); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 1);
        fct_chk_eq_dbl(k.outliers[1], 3);
        fct_chk_eq_dbl(k.outliers[2], 5);
        fct_chk_eq_dbl(k.outliers[3], 7);
        fct_chk_eq_dbl(k.outliers[4], 9);

        tuna_kernel_obs(&k, 0); // Ignored
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 1);
        fct_chk_eq_dbl(k.outliers[1], 3);
        fct_chk_eq_dbl(k.outliers[2], 5);
        fct_chk_eq_dbl(k.outliers[3], 7);
        fct_chk_eq_dbl(k.outliers[4], 9);
    }
    FCT_QTEST_END();

}
FCT_END()
<commit_msg>Complete tuna_kernel_obs testing<commit_after>//--------------------------------------------------------------------------
//
// Copyright (C) 2013 <NAME>
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
//--------------------------------------------------------------------------

#include <tuna/kernel.h>

#include "fct.h"

// Many tests rely on having a known number of outliers
enum { noutliers = 5 };

FCT_BGN()
{
    FCT_QTEST_BGN(observe)
    {
        tuna_kernel k = {};

        // Testing initial behavior before any observations provided
        fct_chk_eq_int(noutliers, sizeof(k.outliers)/sizeof(k.outliers[0]));
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        for (int i = 0; i < noutliers; ++i) {
            fct_chk_eq_dbl(k.outliers[i], 0);
        }

        // Record observations 1, 3, 5, 0, 7, 9, 0 checking state after each

        tuna_kernel_obs(&k, 1); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 0);
        fct_chk_eq_dbl(k.outliers[3], 0);
        fct_chk_eq_dbl(k.outliers[4], 1);

        tuna_kernel_obs(&k, 3); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 0);
        fct_chk_eq_dbl(k.outliers[3], 1);
        fct_chk_eq_dbl(k.outliers[4], 3);

        tuna_kernel_obs(&k, 5); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 1);
        fct_chk_eq_dbl(k.outliers[3], 3);
        fct_chk_eq_dbl(k.outliers[4], 5);

        tuna_kernel_obs(&k, 0); // Ignored
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 0);
        fct_chk_eq_dbl(k.outliers[2], 1);
        fct_chk_eq_dbl(k.outliers[3], 3);
        fct_chk_eq_dbl(k.outliers[4], 5);

        tuna_kernel_obs(&k, 7); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 0);
        fct_chk_eq_dbl(k.outliers[1], 1);
        fct_chk_eq_dbl(k.outliers[2], 3);
        fct_chk_eq_dbl(k.outliers[3], 5);
        fct_chk_eq_dbl(k.outliers[4], 7);

        tuna_kernel_obs(&k, 9); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 1);
        fct_chk_eq_dbl(k.outliers[1], 3);
        fct_chk_eq_dbl(k.outliers[2], 5);
        fct_chk_eq_dbl(k.outliers[3], 7);
        fct_chk_eq_dbl(k.outliers[4], 9);

        tuna_kernel_obs(&k, 0); // Ignored
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 0);
        fct_chk_eq_dbl(k.outliers[0], 1);
        fct_chk_eq_dbl(k.outliers[1], 3);
        fct_chk_eq_dbl(k.outliers[2], 5);
        fct_chk_eq_dbl(k.outliers[3], 7);
        fct_chk_eq_dbl(k.outliers[4], 9);

        // Record elapsed times that enter middle of outliers
        // and ensure that the sorted invariant remains correct

        tuna_kernel_obs(&k, 6); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 1);
        fct_chk_eq_dbl(tuna_stats_avg(&(k.stats)), 1);
        fct_chk_eq_dbl(k.outliers[0], 3);
        fct_chk_eq_dbl(k.outliers[1], 5);
        fct_chk_eq_dbl(k.outliers[2], 6);
        fct_chk_eq_dbl(k.outliers[3], 7);
        fct_chk_eq_dbl(k.outliers[4], 9);

        tuna_kernel_obs(&k, 8); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 2);
        fct_chk_eq_dbl(tuna_stats_avg(&(k.stats)), 2);
        fct_chk_eq_dbl(k.outliers[0], 5);
        fct_chk_eq_dbl(k.outliers[1], 6);
        fct_chk_eq_dbl(k.outliers[2], 7);
        fct_chk_eq_dbl(k.outliers[3], 8);
        fct_chk_eq_dbl(k.outliers[4], 9);

        tuna_kernel_obs(&k, 0); // Ignored
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 2);
        fct_chk_eq_dbl(tuna_stats_avg(&(k.stats)), 2);
        fct_chk_eq_dbl(k.outliers[0], 5);
        fct_chk_eq_dbl(k.outliers[1], 6);
        fct_chk_eq_dbl(k.outliers[2], 7);
        fct_chk_eq_dbl(k.outliers[3], 8);
        fct_chk_eq_dbl(k.outliers[4], 9);

        tuna_kernel_obs(&k, 2); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 3);
        fct_chk_eq_dbl(tuna_stats_avg(&(k.stats)), 2);
        fct_chk_eq_dbl(k.outliers[0], 5);
        fct_chk_eq_dbl(k.outliers[1], 6);
        fct_chk_eq_dbl(k.outliers[2], 7);
        fct_chk_eq_dbl(k.outliers[3], 8);
        fct_chk_eq_dbl(k.outliers[4], 9);

        tuna_kernel_obs(&k, 10); // Recorded
        fct_chk_eq_int(tuna_stats_cnt(&(k.stats)), 4);
        fct_chk_eq_dbl(k.outliers[0],  6);
        fct_chk_eq_dbl(k.outliers[1],  7);
        fct_chk_eq_dbl(k.outliers[2],  8);
        fct_chk_eq_dbl(k.outliers[3],  9);
        fct_chk_eq_dbl(k.outliers[4], 10);

    }
    FCT_QTEST_END();

}
FCT_END()

{'fraction_non_alphanumeric': 0.1882042675617358, 'fraction_numerical': 0.032845840326060895, 'mean_word_length': 2.4305098684210527, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7507520', 'n_tokens_mistral': 3868, 'n_tokens_neox': 3677, 'n_words': 501}