<commit_before>#include "UnitTest++/UnitTest++.h"

#include "StrongAI/AI/CaseBasedAI/CaseBasedAI.hpp"

SUITE( CaseBasedAITest )
{

    TEST( smokeTest )
    {
        CaseBasedAI ai( 0, 0, 0, 0 );

        auto output = ai.output();
        CHECK_EQUAL( 0, output.size() );

        ai.learn( 1 );
    }

    TEST( seeksGoodOutcome )
    {
        CaseBasedAI ai( 1, 1, 1, 2 );

        const std::vector< float > input( { 0 } );
        const std::vector< float > outputToLearn( { 2 } );

        ai.learn( input, outputToLearn, 1 );
        auto actualOutput = ai.output( input );
        CHECK( 2 == actualOutput.at( 0 ) );
    }

    TEST( avoidsBadOutcome )
    {
        CaseBasedAI ai( 1, 1, 1, 2 );

        const std::vector< float > input( { 0 } );
        const std::vector< float > outputToLearn( { 2 } );

        ai.learn( input, outputToLearn, -1 );
        auto actualOutput = ai.output( input );
        CHECK( 2 != actualOutput.at( 0 ) );
    }
}<commit_msg>CaseBasedAI tested for save and load methods<commit_after>#include "UnitTest++/UnitTest++.h"

#include "StrongAI/AI/CaseBasedAI/CaseBasedAI.hpp"

#include <string>
#include <vector>

SUITE( CaseBasedAITest )
{

    TEST( smokeTest )
    {
        CaseBasedAI ai( 0, 0, 0, 0 );

        auto output = ai.output();
        CHECK_EQUAL( 0, output.size() );

        ai.learn( 1 );
    }

    TEST( seeksGoodOutcome )
    {
        CaseBasedAI ai( 1, 1, 1, 2 );

        const std::vector< float > input( { 0 } );
        const std::vector< float > outputToLearn( { 2 } );

        ai.learn( input, outputToLearn, 1 );
        auto actualOutput = ai.output( input );
        CHECK( 2 == actualOutput.at( 0 ) );
    }

    TEST( avoidsBadOutcome )
    {
        CaseBasedAI ai( 1, 1, 1, 2 );

        const std::vector< float > input( { 0 } );
        const std::vector< float > outputToLearn( { 2 } );

        ai.learn( input, outputToLearn, -1 );
        auto actualOutput = ai.output( input );
        CHECK( 2 != actualOutput.at( 0 ) );
    }

    TEST( saveAndLoad )
    {
        const std::string saveFileName = "caseBasedAI.save";
        const std::vector< float > input( { 0 } );
        const std::vector< float > outputToLearn( { 2 } );

        CaseBasedAI teacherAI ( 1, 1, 2, 2 );
        teacherAI.learn( input, outputToLearn, 1 );
        GeneralAI::save< CaseBasedAI >( teacherAI, saveFileName );

        CaseBasedAI studentAI ( 1, 1, 2, 2 );
        GeneralAI::load< CaseBasedAI >( studentAI, saveFileName );
        auto studentOutput = studentAI.output( input );

        CHECK_EQUAL( outputToLearn.at( 0 ), studentOutput.at( 0 ) );

        // Delete save file
        CHECK( !remove( saveFileName.data() ) ) ;
    }
}
{'fraction_non_alphanumeric': 0.1411721341688168, 'fraction_numerical': 0.02248433468485072, 'mean_word_length': 2.177985948477752, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6781625', 'n_tokens_mistral': 969, 'n_tokens_neox': 860, 'n_words': 229}