<commit_before>#!perl -w
#
# Test of ta_data
# 

use strict;
use lib "../../../lib/perl";
use Test;
BEGIN { plan tests => 98 }

use Finance::TA v0.1.2;

print "TA-Lib ", TA_GetVersionString(), "\n";
print "Testing ta_data...\n";

# First, we test all the constants, then the functions

ok( $TA_SOURCELOCATION_MAX_LENGTH > 0 );
ok( $TA_SOURCEINFO_MAX_LENGTH > 0 );
ok( $TA_CATEGORY_MAX_LENGTH > 0 );
ok( $TA_SYMBOL_MAX_LENGTH > 0 );

ok( $TA_CAT_COUNTRY_MAX_LENGTH > 0 );
ok( $TA_CAT_EXCHANGE_MAX_LENGTH > 0 );
ok( $TA_CAT_TYPE_MAX_LENGTH > 0 );

ok( $TA_DEFAULT_CATEGORY, "ZZ.OTHER.OTHER" );
ok( $TA_DEFAULT_CATEGORY_COUNTRY, "ZZ" );
ok( $TA_DEFAULT_CATEGORY_EXCHANGE, "OTHER" );
ok( $TA_DEFAULT_CATEGORY_TYPE, "OTHER" );

print "Testing TA_SourceId...\n";
ok( $TA_ASCII_FILE, 0 );
ok( $TA_SIMULATOR, 1 );
ok( $TA_YAHOO_WEB, 2 );
ok( $TA_SQL, 3 );
ok( $TA_NUM_OF_SOURCE_ID > 0 );

print "Testing TA_SourceFlag...\n";
ok( $TA_NO_FLAGS, 0 );
ok( $TA_REPLACE_ZERO_PRICE_BAR, 1 << 0 );
ok( $TA_DO_NOT_SPLIT_ADJUST, 1 << 1 );
ok( $TA_DO_NOT_VALUE_ADJUST, 1 << 2 );

ok( $TA_DOHLCV, "[Y][M][D][O][H][L][C][V]" );
ok( $TA_DOCHLV, "[Y][M][D][O][C][H][L][V]" );
ok( $TA_DOCV, "[Y][M][D][O][C][V]" );
ok( $TA_DCV, "[Y][M][D][C][V]" );

print "Testing TA_Field...\n";
ok( $TA_ALL, 0 );
ok( $TA_OPEN, 1 << 0 );
ok( $TA_HIGH, 1 << 1 );
ok( $TA_LOW, 1 << 2 );
ok( $TA_CLOSE, 1 << 3 );
ok( $TA_VOLUME, 1 << 4 );
ok( $TA_OPENINTEREST, 1 << 5 );
ok( $TA_TIMESTAMP, 1 << 6 );

print "Testing TA_ReportFlag...\n";
ok( $TA_REPORT_SYMBOL, 1 << 0 );
ok( $TA_REPORT_CATEGORY, 1 << 1 );
ok( $TA_REPORT_SOURCE, 1 << 2 );
ok( $TA_REPORT_TOTAL, 1 << 3 );

print "Testing functions...\n";
my $udb; # Universal DataBase
ok( TA_UDBaseAlloc(\$udb), $TA_SUCCESS );
ok( TA_UDBaseFree($udb), $TA_SUCCESS );
undef $udb;     # IMPORTANT: don't forget to undef the database 
                # after call to &TA_UDBaseFree or segfault may happen!

ok( TA_UDBaseAlloc(\$udb), $TA_SUCCESS );
ok( TA_UDBaseFree($udb), $TA_SUCCESS );

$udb = new TA_UDBase;   # Preferred way of allocating the database
ok( defined $udb );
undef $udb;
$udb = new TA_UDBase;
ok( defined $udb );


print "Testing TA_SIMULATOR data source...\n";
my $sparam = new TA_AddDataSourceParam;
ok( $sparam->{id}, 0 );
ok( $sparam->{flags}, $TA_NO_FLAGS );
ok( $sparam->{period}, 0 );
ok( $sparam->{location}, undef );
ok( $sparam->{info}, undef );
ok( $sparam->{username}, undef );
ok( $sparam->{password}, undef );
ok( $sparam->{category}, undef );
ok( $sparam->{country}, undef );
ok( $sparam->{exchange}, undef );
ok( $sparam->{type}, undef );
ok( $sparam->{symbol}, undef );
ok( $sparam->{name}, undef );
$sparam->{id} = $TA_SIMULATOR;
ok( TA_AddDataSource($udb, $sparam), $TA_SUCCESS );

{
    # Testing string tables
    my @categories = TA_CategoryTable($udb);
    #print "Categories: @categories\n";
    ok( shift(@categories), $TA_SUCCESS );
    ok( $categories[0], "TA_SIM_MRG" );
    ok( $categories[1], "TA_SIM_REF" );
    ok( $categories[2], "ZZ.OTHER.OTHER" );

    # Another way - using shadow class
    @categories = $udb->CategoryTable();
    ok( $categories[0], "TA_SIM_MRG" );
    ok( $categories[1], "TA_SIM_REF" );
    ok( $categories[2], "ZZ.OTHER.OTHER" );
    
    my @symbols = TA_SymbolTable($udb, "TA_SIM_REF");
    #print "Symbols @symbols\n";
    ok( shift(@symbols), $TA_SUCCESS );
    ok( $symbols[0], "DAILY_REF_0" );
    ok( $symbols[1], "INTRA_REF_0" );

    # Another way - using shadow class
    @symbols = $udb->SymbolTable("TA_SIM_REF");
    ok( $symbols[0], "DAILY_REF_0" );
    ok( $symbols[1], "INTRA_REF_0" );

    # Negative testing
    @symbols = TA_SymbolTable($udb, "BOGUS");
    ok( shift(@symbols), $TA_CATEGORY_NOT_FOUND );
    ok( $udb->SymbolTable("BOGUS"), undef );

    my $udbx;  # undef
    @categories = TA_CategoryTable($udbx);
    ok( shift(@categories), $TA_BAD_PARAM );
    @symbols = TA_SymbolTable($udbx, "BOGUS");
    ok( shift(@symbols), $TA_BAD_PARAM );
}

{
    # Testing history
 
    my $history1 = new TA_History($udb, "TA_SIM_REF", "DAILY_REF_0", $TA_DAILY, undef, undef, $TA_ALL);
    ok( defined $history1 );
    ok( $history1->{retCode}, $TA_SUCCESS );<commit_msg>updated to align with recent changes in ta_data (TA_SIM_MRG)<commit_after>#!perl -w
#
# Test of ta_data
# 

use strict;
use lib "../../../lib/perl";
use Test;
BEGIN { plan tests => 96 }

use Finance::TA v0.1.2;

print "TA-Lib ", TA_GetVersionString(), "\n";
print "Testing ta_data...\n";

# First, we test all the constants, then the functions

ok( $TA_SOURCELOCATION_MAX_LENGTH > 0 );
ok( $TA_SOURCEINFO_MAX_LENGTH > 0 );
ok( $TA_CATEGORY_MAX_LENGTH > 0 );
ok( $TA_SYMBOL_MAX_LENGTH > 0 );

ok( $TA_CAT_COUNTRY_MAX_LENGTH > 0 );
ok( $TA_CAT_EXCHANGE_MAX_LENGTH > 0 );
ok( $TA_CAT_TYPE_MAX_LENGTH > 0 );

ok( $TA_DEFAULT_CATEGORY, "ZZ.OTHER.OTHER" );
ok( $TA_DEFAULT_CATEGORY_COUNTRY, "ZZ" );
ok( $TA_DEFAULT_CATEGORY_EXCHANGE, "OTHER" );
ok( $TA_DEFAULT_CATEGORY_TYPE, "OTHER" );

print "Testing TA_SourceId...\n";
ok( $TA_ASCII_FILE, 0 );
ok( $TA_SIMULATOR, 1 );
ok( $TA_YAHOO_WEB, 2 );
ok( $TA_SQL, 3 );
ok( $TA_NUM_OF_SOURCE_ID > 0 );

print "Testing TA_SourceFlag...\n";
ok( $TA_NO_FLAGS, 0 );
ok( $TA_REPLACE_ZERO_PRICE_BAR, 1 << 0 );
ok( $TA_DO_NOT_SPLIT_ADJUST, 1 << 1 );
ok( $TA_DO_NOT_VALUE_ADJUST, 1 << 2 );

ok( $TA_DOHLCV, "[Y][M][D][O][H][L][C][V]" );
ok( $TA_DOCHLV, "[Y][M][D][O][C][H][L][V]" );
ok( $TA_DOCV, "[Y][M][D][O][C][V]" );
ok( $TA_DCV, "[Y][M][D][C][V]" );

print "Testing TA_Field...\n";
ok( $TA_ALL, 0 );
ok( $TA_OPEN, 1 << 0 );
ok( $TA_HIGH, 1 << 1 );
ok( $TA_LOW, 1 << 2 );
ok( $TA_CLOSE, 1 << 3 );
ok( $TA_VOLUME, 1 << 4 );
ok( $TA_OPENINTEREST, 1 << 5 );
ok( $TA_TIMESTAMP, 1 << 6 );

print "Testing TA_ReportFlag...\n";
ok( $TA_REPORT_SYMBOL, 1 << 0 );
ok( $TA_REPORT_CATEGORY, 1 << 1 );
ok( $TA_REPORT_SOURCE, 1 << 2 );
ok( $TA_REPORT_TOTAL, 1 << 3 );

print "Testing functions...\n";
my $udb; # Universal DataBase
ok( TA_UDBaseAlloc(\$udb), $TA_SUCCESS );
ok( TA_UDBaseFree($udb), $TA_SUCCESS );
undef $udb;     # IMPORTANT: don't forget to undef the database 
                # after call to &TA_UDBaseFree or segfault may happen!

ok( TA_UDBaseAlloc(\$udb), $TA_SUCCESS );
ok( TA_UDBaseFree($udb), $TA_SUCCESS );

$udb = new TA_UDBase;   # Preferred way of allocating the database
ok( defined $udb );
undef $udb;
$udb = new TA_UDBase;
ok( defined $udb );


print "Testing TA_SIMULATOR data source...\n";
my $sparam = new TA_AddDataSourceParam;
ok( $sparam->{id}, 0 );
ok( $sparam->{flags}, $TA_NO_FLAGS );
ok( $sparam->{period}, 0 );
ok( $sparam->{location}, undef );
ok( $sparam->{info}, undef );
ok( $sparam->{username}, undef );
ok( $sparam->{password}, undef );
ok( $sparam->{category}, undef );
ok( $sparam->{country}, undef );
ok( $sparam->{exchange}, undef );
ok( $sparam->{type}, undef );
ok( $sparam->{symbol}, undef );
ok( $sparam->{name}, undef );
$sparam->{id} = $TA_SIMULATOR;
ok( TA_AddDataSource($udb, $sparam), $TA_SUCCESS );

{
    # Testing string tables
    my @categories = TA_CategoryTable($udb);
    #print "Categories: @categories\n";
    ok( shift(@categories), $TA_SUCCESS );
    #ok( $categories[0], "TA_SIM_MRG" );
    ok( $categories[0], "TA_SIM_REF" );
    ok( $categories[1], "ZZ.OTHER.OTHER" );

    # Another way - using shadow class
    @categories = $udb->CategoryTable();
    #ok( $categories[0], "TA_SIM_MRG" );
    ok( $categories[0], "TA_SIM_REF" );
    ok( $categories[1], "ZZ.OTHER.OTHER" );
    
    my @symbols = TA_SymbolTable($udb, "TA_SIM_REF");
    #print "Symbols @symbols\n";
    ok( shift(@symbols), $TA_SUCCESS );
    ok( $symbols[0], "DAILY_REF_0" );
    ok( $symbols[1], "INTRA_REF_0" );

    # Another way - using shadow class
    @symbols = $udb->SymbolTable("TA_SIM_REF");
    ok( $symbols[0], "DAILY_REF_0" );
    ok( $symbols[1], "INTRA_REF_0" );

    # Negative testing
    @symbols = TA_SymbolTable($udb, "BOGUS");
    ok( shift(@symbols), $TA_CATEGORY_NOT_FOUND );
    ok( $udb->SymbolTable("BOGUS"), undef );

    my $udbx;  # undef
    @categories = TA_CategoryTable($udbx);
    ok( shift(@categories), $TA_BAD_PARAM );
    @symbols = TA_SymbolTable($udbx, "BOGUS");
    ok( shift(@symbols), $TA_BAD_PARAM );
}

{
    # Testing history
 
    my $history1 = new TA_History($udb, "TA_SIM_REF", "DAILY_REF_0", $TA_DAILY, undef, undef, $TA_ALL);
    ok( defined $history1 );
    ok( $history1->{retCode}, $TA_SUCCESS );
{'fraction_non_alphanumeric': 0.20021477150698008, 'fraction_numerical': 0.01598854551962773, 'mean_word_length': 4.328671328671328, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 57, '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': '4720251', 'n_tokens_mistral': 3733, 'n_tokens_neox': 3446, 'n_words': 784}