<commit_before>#pragma once

#include <cmath>
#include <iostream>
#include <map>
#include <type_traits>
#include <vector>

#include "../enum/validation_method.h"
#include "../kernel_argument/kernel_argument.h"
#include "../utility/logger.h"

namespace ktt
{

class ResultValidator
{
public:
    // Constructor
    ResultValidator(Logger* logger);

    // Core methods
    bool validateArgumentWithClass(const size_t kernelId, const std::vector<KernelArgument>& resultArguments) const;
    bool validateArgumentWithKernel(const size_t kernelId, const std::vector<KernelArgument>& resultArguments) const;
    void setReferenceClassResult(const size_t kernelId, const std::vector<KernelArgument>& classResult);
    void setReferenceKernelResult(const size_t kernelId, const std::vector<KernelArgument>& kernelResult);
    bool hasReferenceClassResult(const size_t kernelId) const;
    bool hasReferenceKernelResult(const size_t kernelId) const;
    void clearReferenceResults();

    // Setters
    void setToleranceThreshold(const double toleranceThreshold);
    void setValidationMethod(const ValidationMethod& validationMethod);
    void setValidationRange(const size_t validationRange);

    // Getters
    double getToleranceThreshold() const;
    ValidationMethod getValidationMethod() const;

private:
    // Attributes
    double toleranceThreshold;
    ValidationMethod validationMethod;
    size_t validationRange;
    std::map<size_t, std::vector<KernelArgument>> referenceClassResultMap;
    std::map<size_t, std::vector<KernelArgument>> referenceKernelResultMap;
    Logger* logger;

    // Helper methods
    bool validateArguments(const std::vector<KernelArgument>& resultArguments, const std::vector<KernelArgument>& referenceArguments) const;
    KernelArgument findArgument(const size_t argumentId, const std::vector<KernelArgument>& arguments) const;

    template <typename T> bool validateResult(const std::vector<T>& result, const std::vector<T>& referenceResult) const
    {
        if (validationRange == 0 && (result.size() != referenceResult.size()))
        {
            logger->log(std::string("Number of elements in results differs, reference size: ") + std::to_string(referenceResult.size())
                + "; result size: " + std::to_string(result.size()));
            return false;
        }
        return validateResultInner(result, referenceResult, std::is_floating_point<T>());
    }

    template <typename T> bool validateResultInner(const std::vector<T>& result,
        const std::vector<T>& referenceResult, std::true_type) const
    {
        size_t iters;
        if (validationRange == 0)
            iters =  result.size();
        else
            iters = validationRange;<commit_msg>improved validation check<commit_after>#pragma once

#include <cmath>
#include <iostream>
#include <map>
#include <type_traits>
#include <vector>

#include "../enum/validation_method.h"
#include "../kernel_argument/kernel_argument.h"
#include "../utility/logger.h"

namespace ktt
{

class ResultValidator
{
public:
    // Constructor
    ResultValidator(Logger* logger);

    // Core methods
    bool validateArgumentWithClass(const size_t kernelId, const std::vector<KernelArgument>& resultArguments) const;
    bool validateArgumentWithKernel(const size_t kernelId, const std::vector<KernelArgument>& resultArguments) const;
    void setReferenceClassResult(const size_t kernelId, const std::vector<KernelArgument>& classResult);
    void setReferenceKernelResult(const size_t kernelId, const std::vector<KernelArgument>& kernelResult);
    bool hasReferenceClassResult(const size_t kernelId) const;
    bool hasReferenceKernelResult(const size_t kernelId) const;
    void clearReferenceResults();

    // Setters
    void setToleranceThreshold(const double toleranceThreshold);
    void setValidationMethod(const ValidationMethod& validationMethod);
    void setValidationRange(const size_t validationRange);

    // Getters
    double getToleranceThreshold() const;
    ValidationMethod getValidationMethod() const;

private:
    // Attributes
    double toleranceThreshold;
    ValidationMethod validationMethod;
    size_t validationRange;
    std::map<size_t, std::vector<KernelArgument>> referenceClassResultMap;
    std::map<size_t, std::vector<KernelArgument>> referenceKernelResultMap;
    Logger* logger;

    // Helper methods
    bool validateArguments(const std::vector<KernelArgument>& resultArguments, const std::vector<KernelArgument>& referenceArguments) const;
    KernelArgument findArgument(const size_t argumentId, const std::vector<KernelArgument>& arguments) const;

    template <typename T> bool validateResult(const std::vector<T>& result, const std::vector<T>& referenceResult) const
    {
        if (validationRange == 0 && (result.size() != referenceResult.size()))
        {
            logger->log(std::string("Number of elements in results differs, reference size: ") + std::to_string(referenceResult.size())
                + "; result size: " + std::to_string(result.size()));
            return false;
        }
        if ((result.size() < validationRange && referenceResult.size() < validationRange))
        {
            logger->log(std::string("Insufficient Number of elements (less than required by validation range, reference size: ") + std::to_string(referenceResult.size())
                + "; result size: " + std::to_string(result.size()));
            return false;
        }
        return validateResultInner(result, referenceResult, std::is_floating_point<T>());
    }

    template <typename T> bool validateResultInner(const std::vector<T>& result,
        const std::vector<T>& referenceResult, std::true_type) const
    {
        size_t iters;
        if (validationRange == 0)
            iters =  result.size();
        else
            iters = validationRange;
{'fraction_non_alphanumeric': 0.10592858363232531, 'fraction_numerical': 0.0006834102169827439, 'mean_word_length': 4.245519713261649, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 52, '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': '1773917', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1506, 'n_words': 384}