Beispiel #1
0
int
test_strcpy( newstr *s )
{
	int failed = 0;
	int numstrings = 1000, i;

	/* Copying null string should reset string */
	newstr_empty( s );
	for ( i=0; i<numstrings; ++i ) {
		newstr_strcpy( s, "1" );
		newstr_strcpy( s, "" );
		if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) )
			failed++;
	}

	newstr_empty( s );
	for ( i=0; i<numstrings; ++i ) {
		newstr_strcpy( s, "1" );
		if ( test_consistency( s, 1, __FUNCTION__ ) || test_identity( s, "1" ) )
			failed++;
	}

	newstr_empty( s );
	for ( i=0; i<numstrings; ++i ) {
		newstr_strcpy( s, "XXOO" );
		if ( test_consistency( s, 4, __FUNCTION__ ) || test_identity( s, "XXOO" ) )
			failed++;
	}

	return failed;
}
Beispiel #2
0
int
test_addchar( newstr *s )
{
	int failed = 0;
	int numshort = 5, numchars = 1000, i;

	/* ...appending '\0' characters won't increase length */
	newstr_empty( s );
	for ( i=0; i<numshort; ++i )
		newstr_addchar( s, '\0' );
	if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) )
		failed++;

	/* ...build "11111" with newstr_addchar */
	newstr_empty( s );
	for ( i=0; i<numshort; ++i )
		newstr_addchar( s, '1' );
	if ( test_consistency( s, 5, __FUNCTION__ ) || test_identity( s, "11111" ) )
		failed++;

	newstr_empty( s );
	for ( i=0; i<numchars; ++i ) {
		newstr_addchar( s, ( i % 64 ) + 64);
	}
	if ( test_consistency( s, numchars, __FUNCTION__ ) )
		failed++;

	return failed;
}
Beispiel #3
0
int
test_findreplace( newstr *s )
{
	int failed = 0;
	int numstrings = 1000, i;
	char segment[]="0123456789";
	for ( i=0; i<numstrings; ++i ) {
		newstr_strcpy( s, segment );
		newstr_findreplace( s, "234", "" );
	}
	failed += test_consistency( s, 7, __FUNCTION__ );
	for ( i=0; i<numstrings; ++i ) {
		newstr_strcpy( s, segment );
		newstr_findreplace( s, "234", "223344" );
	}
	failed += test_consistency( s, 13, __FUNCTION__ );
	return failed;
}
Beispiel #4
0
int
test_segcat( newstr *s )
{
	int failed = 0;
	int numstrings = 1000, i;
	char segment[]="0123456789";
	char *start=&(segment[2]), *end=&(segment[5]);
	newstr_empty( s );
	for ( i=0; i<numstrings; ++i ) {
		newstr_segcat( s, start, end );
	}
	failed = test_consistency( s, 3*numstrings, __FUNCTION__ );
	return failed;
}
Beispiel #5
0
int
test_empty( newstr *s )
{
	int failed = 0;
	int numchars = 1000, i, j;
	newstr_empty( s );
	for ( i=0; i<numchars; ++i ) {
		for ( j=0; j<i; ++j )
			newstr_addchar( s, 'x' );
		newstr_empty( s );
		if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) )
			failed++;
	}
	return failed;
}
Beispiel #6
0
int
test_segcpy( newstr *s )
{
	int failed = 0;
	int numstrings = 1000, i;
	char segment[]="0123456789";
	char *start=&(segment[2]), *end=&(segment[5]);
	newstr_empty( s );
	for ( i=0; i<numstrings; ++i ) {
		newstr_segcpy( s, start, end );
		if ( test_consistency( s, 3, __FUNCTION__ ) || test_identity( s, "234" ) )
			failed++;
	}
	return failed;
}
Beispiel #7
0
int
test_strcat( newstr *s )
{
	int failed = 0;
	int numshort = 5, numstrings = 1000, i;

	/* ...adding empty strings to an empty string shouldn't change length */
	newstr_empty( s );
	for ( i=0; i<numstrings; ++i )
		newstr_strcat( s, "" );
	if ( test_consistency( s, 0, __FUNCTION__ ) || test_identity( s, "" ) )
		failed++;

	/* ...adding empty strings to a defined string shouldn't change string */
	newstr_strcpy( s, "1" );
	for ( i=0; i<numstrings; ++i )
		newstr_strcat( s, "" );
	if ( test_consistency( s, 1, __FUNCTION__ ) || test_identity( s, "1" ) )
		failed++;

	/* ...build "1111" with newstr_strcat */
	newstr_empty( s );
	for ( i=0; i<numshort; ++i )
		newstr_strcat( s, "1" );
	if ( test_consistency( s, numshort, __FUNCTION__ ) || test_identity( s, "11111" ) )
		failed++;

	/* ...build "xoxoxoxoxo" with newstr_strcat */
	newstr_empty( s );
	for ( i=0; i<numshort; ++i )
		newstr_strcat( s, "xo" );
	if ( test_consistency( s, numshort*2, __FUNCTION__ ) || test_identity( s, "xoxoxoxoxo" ) )
		failed++;

	newstr_empty( s );
	for ( i=0; i<numstrings; ++i )
		newstr_strcat( s, "1" );
	if ( test_consistency( s, numstrings, __FUNCTION__ ) )
		failed++;

	newstr_empty( s );
	for ( i=0; i<numstrings; ++i ) {
		newstr_strcat( s, "XXOO" );
	}
	failed += test_consistency( s, numstrings*4, __FUNCTION__ );
	return failed;
}
Beispiel #8
0
premium_tax::premium_tax
    (mcenum_state              tax_state
    ,mcenum_state              domicile
    ,bool                      amortize_premium_load
    ,product_database   const& db
    ,stratified_charges const& strata
    )
    :tax_state_              (tax_state)
    ,domicile_               (domicile)
    ,amortize_premium_load_  (amortize_premium_load)
    ,levy_rate_              (0.0)   // Reset below.
    ,load_rate_              (0.0)   // Reset below.
    ,tax_state_load_rate_    (0.0)   // Reset below.
    ,domiciliary_load_rate_  (0.0)   // Reset below.
    ,maximum_load_rate_      (0.0)   // Reset below.
    ,minimum_load_rate_      (0.0)   // Reset below.
    ,is_tiered_in_tax_state_ (false) // Reset below.
    ,is_tiered_in_domicile_  (false) // Reset below.
    ,is_retaliatory_         (false) // Reset below.
    ,varies_by_state_        (false) // Reset below.
    ,load_rate_is_levy_rate_ (false) // Reset below.
    ,ytd_taxable_premium_    (0.0)
    ,ytd_load_               (0.0)
    ,ytd_load_in_tax_state_  (0.0)
    ,ytd_load_in_domicile_   (0.0)
{
    is_tiered_in_tax_state_ = strata.premium_tax_is_tiered(tax_state_);
    is_tiered_in_domicile_  = strata.premium_tax_is_tiered(domicile_ );

    is_retaliatory_ = premium_tax_is_retaliatory(tax_state_, domicile_);

    varies_by_state_ = db.varies_by_state(DB_PremTaxLoad);

    load_rate_is_levy_rate_ = db.are_equivalent(DB_PremTaxLoad, DB_PremTaxRate);

    double tax_state_levy_rate   = 0.0;
    double domiciliary_levy_rate = 0.0;
    if(!amortize_premium_load_)
        {
        database_index index0 = db.index().state(tax_state_);
        tax_state_levy_rate    = db.Query(DB_PremTaxRate, index0);
        tax_state_load_rate_   = db.Query(DB_PremTaxLoad, index0);
        database_index index1 = db.index().state(domicile_);
        domiciliary_levy_rate  = db.Query(DB_PremTaxRate, index1);
        domiciliary_load_rate_ = db.Query(DB_PremTaxLoad, index1);
        }

    if(is_retaliatory_)
        {
        levy_rate_ = std::max(tax_state_levy_rate , domiciliary_levy_rate );
        load_rate_ = std::max(tax_state_load_rate_, domiciliary_load_rate_);
        }
    else
        {
        levy_rate_ = tax_state_levy_rate ;
        load_rate_ = tax_state_load_rate_;
        }

    maximum_load_rate_ = ascertain_maximum_load_rate(strata);
    minimum_load_rate_ = ascertain_minimum_load_rate(strata);

    test_consistency();
}
Beispiel #9
0
int main (int argc, char **argv)
{
    /* Ignore unused parameters. */
    (void)argc;
    (void)argv;

    int ret = 0;

    ret += test_consistency(0.5, 0., 0., 1., 4.5);
    ret += test_consistency(0.9, 0., 0., 1., 4.5);
    ret += test_consistency(0.01, 0., 0., 1., 4.5);

    ret += test_consistency(0.5, 1., 0., 1., 4.5);
    ret += test_consistency(0.9, 1., 0., 1., 4.5);
    ret += test_consistency(0.01, 1., 0., 1., 4.5);

    ret += test_consistency(0.5, 0., -0.4, 1., 4.5);
    ret += test_consistency(0.9, 0., -0.4, 1., 4.5);
    ret += test_consistency(0.01, 0., -0.4, 1., 4.5);

    ret += test_consistency(0.5, 0.9, -0.9, 2., 2.);
    ret += test_consistency(0.9, 0.9, -0.9, 3., 3.);
    ret += test_consistency(0.01, 0.9, -0.9, 4., 4.);

    ret += test_consistency_T4(0.5, 0., 0., 1., 4.5);
    ret += test_consistency_T4(0.9, 0., 0., 1., 4.5);
    ret += test_consistency_T4(0.01, 0., 0., 1., 4.5);

    ret += test_consistency_T4(0.5, 1., 0., 1., 4.5);
    ret += test_consistency_T4(0.9, 1., 0., 1., 4.5);
    ret += test_consistency_T4(0.01, 1., 0., 1., 4.5);

    ret += test_consistency_T4(0.5, 0., -0.4, 1., 4.5);
    ret += test_consistency_T4(0.9, 0., -0.4, 1., 4.5);
    ret += test_consistency_T4(0.01, 0., -0.4, 1., 4.5);

    ret += test_consistency_T4(0.5, 0.9, -0.9, 2., 2.);
    ret += test_consistency_T4(0.9, 0.9, -0.9, 3., 3.);
    ret += test_consistency_T4(0.01, 0.9, -0.9, 4., 4.);

    fprintf(stdout, "Testing tidal terms.\n");
    for (UINT4 idx=1;idx<=9;idx++) {
      ret += test_tidal_F2(0.1*((REAL8)idx));
      ret += test_tidal_T2(0.1*((REAL8)idx));
      ret += test_tidal_T4(0.1*((REAL8)idx));
    }

    fprintf(stdout, "Testing dL.\n");
    for (UINT4 idx=1;idx<=9;idx++) {
      ret += test_consistency_dL(0.1*((REAL8)idx),0.2,0.3,1.,2.);
      ret += test_consistency_dL(0.1*((REAL8)idx),0.2,0.3,1.,2.);
      ret += test_consistency_dL(0.1*((REAL8)idx),0.2,0.3,1.,2.);
    }

    if (ret == 0)
    {
        fprintf(stdout, "\nAll PNCoefficients tests passed.\n");
    }
    else
    {
        fprintf(stderr, "\nFAILURE: %u PNCoefficients comparisons incorrect.\n", ret);
    }

    return ret;
}