static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); /* Clear the unstable periods from previous tests. */ retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MFI, 0 ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; /* Make a simple first call. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_INTERNAL_ERROR(133); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[0].in ); break; default: retCode = TA_INTERNAL_ERROR(134); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); setInputBuffer( 0, history->high, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[1].in ); break; default: retCode = TA_INTERNAL_ERROR(135); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); setInputBuffer( 1, history->low, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_MFI_TEST: retCode = TA_MFI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_AD_TEST: retCode = TA_AD( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_ADOSC_3_10_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 3, 10, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_ADOSC_5_2_TEST: retCode = TA_ADOSC( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, 5, 2, &outBegIdx, &outNbElement, gBuffer[2].in ); break; default: retCode = TA_INTERNAL_ERROR(136); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].in, 0 ); setInputBuffer( 2, history->close, history->nbBars ); if( test->doRangeTestFlag ) { /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; testParam.volume = history->volume; switch( test->theFunction ) { case TA_MFI_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MFI, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; break; case TA_AD_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, TA_DO_NOT_COMPARE ); if( errNb != TA_TEST_PASS ) return errNb; break; case TA_ADOSC_3_10_TEST: case TA_ADOSC_5_2_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 1, TA_DO_NOT_COMPARE ); if( errNb != TA_TEST_PASS ) return errNb; break; default: break; } } /* Check for fix #1359452 - AD RAnge not working as expected. */ if( test->theFunction == TA_AD_TEST ) { gBuffer[0].out0[0] = -1.0; gBuffer[0].out0[1] = -1.0; retCode = TA_AD( 0, 0, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, &gBuffer[0].out0[0] ); if( retCode != TA_SUCCESS ) { printf( "Failed AD call for fix #1359452 [%d]\n", retCode ); return TA_TEST_FAIL_BUG1359452_1; } if( gBuffer[0].out0[0] == -1.0 ) { printf( "Failed AD call for fix #1359452 out0[0] == -1\n" ); return TA_TEST_FAIL_BUG1359452_2; } retCode = TA_AD( 1, 1, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, history->volume, &outBegIdx, &outNbElement, &gBuffer[0].out0[1] ); if( retCode != TA_SUCCESS ) { printf( "Failed AD call for fix #1359452 [%d]\n", retCode ); return TA_TEST_FAIL_BUG1359452_3; } if( gBuffer[0].out0[1] == -1.0 ) { printf( "Failed AD call for fix #1359452 out0[1] == -1\n" ); return TA_TEST_FAIL_BUG1359452_4; } /* The two values are to be different. */ if( gBuffer[0].out0[1] == gBuffer[0].out0[0] ) { printf( "Failed AD logic for fix #1359452\n" ); return TA_TEST_FAIL_BUG1359452_5; } } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RangeTestParam testParam; ErrorNumber errNb; TA_RetCode retCode; (void)test; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->open, history->nbBars ); setInputBuffer( 1, history->high, history->nbBars ); setInputBuffer( 2, history->low, history->nbBars ); setInputBuffer( 3, history->close, history->nbBars ); #if 0 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Test for specific value not yet implemented */ /* Make a simple first call. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_INTERNAL_ERROR(133); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].in ); break; default: retCode = TA_INTERNAL_ERROR(134); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); setInputBuffer( 0, history->high, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[1].in ); break; default: retCode = TA_INTERNAL_ERROR(135); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); setInputBuffer( 1, history->low, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_CCI_TEST: retCode = TA_CCI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_WILLR_TEST: retCode = TA_WILLR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[2].in ); break; default: retCode = TA_INTERNAL_ERROR(136); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call to TA_MA should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].in, 0 ); setInputBuffer( 2, history->close, history->nbBars ); #endif /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.open = history->open; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; testParam.paramHolder = NULL; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( testParam.paramHolder ) { retCode = TA_ParamHolderFree( testParam.paramHolder ); if( retCode != TA_SUCCESS ) { printf( "TA_ParamHolderFree failed [%d]\n", retCode ); return TA_TSTCDL_PARAMHOLDERFREE_FAIL; } } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->open, history->nbBars ); setInputBuffer( 1, history->high, history->nbBars ); setInputBuffer( 2, history->low, history->nbBars ); setInputBuffer( 3, history->close, history->nbBars ); /* Make a simple first call. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_INTERNAL_ERROR(172); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; default: retCode = TA_INTERNAL_ERROR(173); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); setInputBuffer( 0, history->open, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[1].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[1].in ); break; default: retCode = TA_INTERNAL_ERROR(174); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); setInputBuffer( 1, history->high, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[2].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[2].in ); break; default: retCode = TA_INTERNAL_ERROR(175); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[3].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].in, 0 ); setInputBuffer( 2, history->low, history->nbBars ); /* Make another call where the input and the output are the * same buffer. */ switch( test->theFunction ) { case TA_BOP_TEST: retCode = TA_BOP( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TA_AVGPRICE_TEST: retCode = TA_AVGPRICE( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, gBuffer[3].in, &outBegIdx, &outNbElement, gBuffer[3].in ); break; default: retCode = TA_INTERNAL_ERROR(176); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->open,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].in, 0 ); setInputBuffer( 3, history->close, history->nbBars ); /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.open = history->open; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( TA_Libc *libHandle, const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); /* Set the unstable period requested for that test. */ switch( test->optInMethod_3 ) { case TA_STOCH_EXPONENTIAL: retCode = TA_SetUnstablePeriod( libHandle, TA_FUNC_UNST_EMA, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; break; default: /* No unstable period for other methods. */ break; } /* Make a simple first call. */ retCode = TA_STOCH( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInKPeriod_0, test->optInKSlowPeriod_1, test->optInDPeriod_2, test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out1 ); errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_STOCH( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInKPeriod_0, test->optInKSlowPeriod_1, test->optInDPeriod_2, test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[0].in, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].in, 1 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( libHandle, rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 2 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); /* Make a simple first call. */ retCode = TA_STDDEV( test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod, test->optInNbDeviation_1, &outBegIdx, &outNbElement, gBuffer[0].out0 ); errNb = checkDataSame( gBuffer[0].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_STDDEV( test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod, test->optInNbDeviation_1, &outBegIdx, &outNbElement, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; const TA_Real *referenceInput; TA_Integer *intBuffer; int size, i; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); /* Change the input to MEDPRICE for some tests. */ switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: case TA_HT_DCPHASE_TEST: case TA_HT_TRENDLINE_TEST: case TA_HT_TRENDMODE_TEST: TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[0].in ); /* Will be use as reference */ TA_MEDPRICE( 0, history->nbBars-1, history->high, history->low, &outBegIdx, &outNbElement, gBuffer[1].in ); referenceInput = gBuffer[1].in; break; default: referenceInput = history->close; } /* Make a simple first call. */ size = (test->endIdx-test->startIdx)+1; switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: retCode = TA_HT_DCPERIOD( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_HT_DCPHASE_TEST: retCode = TA_HT_DCPHASE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_HT_TRENDLINE_TEST: retCode = TA_HT_TRENDLINE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TA_HT_TRENDMODE_TEST: ALLOC_INT_BUFFER(size); retCode = TA_HT_TRENDMODE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, &intBuffer[1] ); FREE_INT_BUFFER( gBuffer[0].out0, outNbElement ); break; default: retCode = TA_INTERNAL_ERROR(133); } /* Check that the input were preserved. */ errNb = checkDataSame( gBuffer[0].in, referenceInput, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output * are the same buffer. */ switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: retCode = TA_HT_DCPERIOD( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_HT_DCPHASE_TEST: retCode = TA_HT_DCPHASE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_HT_TRENDLINE_TEST: retCode = TA_HT_TRENDLINE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, gBuffer[0].in ); break; case TA_HT_TRENDMODE_TEST: ALLOC_INT_BUFFER(size); retCode = TA_HT_TRENDMODE( test->startIdx, test->endIdx, gBuffer[0].in, &outBegIdx, &outNbElement, &intBuffer[1] ); FREE_INT_BUFFER( gBuffer[0].in, outNbElement ); break; default: retCode = TA_INTERNAL_ERROR(134); } /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.price = referenceInput; if( test->doRangeTestFlag ) { switch( test->theFunction ) { case TA_HT_DCPERIOD_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_DCPERIOD, (void *)&testParam, 1, 0 ); break; case TA_HT_DCPHASE_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_DCPHASE, (void *)&testParam, 1, 360 ); break; case TA_HT_TRENDLINE_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_TRENDLINE, (void *)&testParam, 1, 0 ); break; case TA_HT_TRENDMODE_TEST: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_HT_TRENDMODE, (void *)&testParam, 1, 0 ); break; default: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 1, 0 ); } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( TA_Libc *libHandle, const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; const TA_Real *highPtr; const TA_Real *lowPtr; TA_Integer nbPriceBar; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ if( test->useWilderData ) { highPtr = wilderHigh; lowPtr = wilderLow; nbPriceBar = WILDER_NB_BAR; } else { highPtr = history->high; lowPtr = history->low; nbPriceBar = history->nbBars; } setInputBuffer( 0, highPtr, nbPriceBar ); setInputBuffer( 1, lowPtr, nbPriceBar ); /* Make a simple first call. */ retCode = TA_SAR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInAcceleration, test->optInMaximum, &outBegIdx, &outNbElement, gBuffer[0].out0 ); errNb = checkDataSame( gBuffer[0].in, highPtr, nbPriceBar ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, lowPtr, nbPriceBar ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_SAR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInAcceleration, test->optInMaximum, &outBegIdx, &outNbElement, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Make sure the other input is untouched. */ errNb = checkDataSame( gBuffer[0].in, highPtr, nbPriceBar ); if( errNb != TA_TEST_PASS ) return errNb; /* Repeat that last test but with the first parameter this time. */ /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, highPtr, nbPriceBar ); setInputBuffer( 1, lowPtr, nbPriceBar ); /* Make another call where the input and the output are the * same buffer. */ retCode = TA_SAR( libHandle, test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInAcceleration, test->optInMaximum, &outBegIdx, &outNbElement, gBuffer[0].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Make sure the other input is untouched. */ errNb = checkDataSame( gBuffer[1].in, lowPtr, nbPriceBar); if( errNb != TA_TEST_PASS ) return errNb; return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, 0 ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->close, history->nbBars ); setInputBuffer( 1, history->close, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); setInputBuffer( 3, history->close, history->nbBars ); TA_SetCompatibility( (TA_Compatibility)test->compatibility ); /* Make a simple first call. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[0].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out1, gBuffer[0].out2 ); errNb = checkDataSame( gBuffer[0].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 ); CHECK_EXPECTED_VALUE( gBuffer[0].out2, 2 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[1].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[1].in, gBuffer[1].out1, gBuffer[1].out2 ); /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].in, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].out1, 1 ); CHECK_EXPECTED_VALUE( gBuffer[1].out2, 2 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[2].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[2].out1, gBuffer[2].in, gBuffer[2].out2 ); /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[1].out1, gBuffer[2].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[2].out1, 0 ); CHECK_EXPECTED_VALUE( gBuffer[2].in, 1 ); CHECK_EXPECTED_VALUE( gBuffer[2].out2, 2 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_BBANDS( test->startIdx, test->endIdx, gBuffer[3].in, test->optInTimePeriod, test->optInNbDevUp, test->optInNbDevDn, (TA_MAType)test->optInMethod_3, &outBegIdx, &outNbElement, gBuffer[3].out0, gBuffer[3].out1, gBuffer[3].in ); /* The previous call should have the same output * as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[2].out2, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[3].out1, 1 ); CHECK_EXPECTED_VALUE( gBuffer[3].in, 2 ); /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.close = history->close; if( test->doRangeTestFlag ) { if( test->optInMethod_3 == TA_MAType_EMA ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 3, 0 ); } else { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_NONE, (void *)&testParam, 3, 0 ); } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); setInputBuffer( 3, history->high, history->nbBars ); /* Make a simple first call. */ switch( test->id ) { case TST_MINUS_DM: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MINUS_DM, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_MINUS_DM( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_MINUS_DI: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_MINUS_DI, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_MINUS_DI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_DX: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_DX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_DX( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_ADX: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_ADX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_ADX( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_PLUS_DM: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_PLUS_DM, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_PLUS_DM( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_PLUS_DI: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_PLUS_DI, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_PLUS_DI( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; case TST_ADXR: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_ADX, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; retCode = TA_ADXR( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[0].out0 ); break; default: retCode = TA_BAD_PARAM; } /* Verify that the inputs were preserved. */ errNb = checkDataSame( gBuffer[0].in, history->high, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); outBegIdx = outNbElement = 0; /* Make another call where the input and the output are the * same buffer. */ switch( test->id ) { case TST_MINUS_DM: retCode = TA_MINUS_DM( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_MINUS_DI: retCode = TA_MINUS_DI( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_DX: retCode = TA_DX( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_ADX: retCode = TA_ADX( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_PLUS_DM: retCode = TA_PLUS_DM( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_PLUS_DI: retCode = TA_PLUS_DI( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; case TST_ADXR: retCode = TA_ADXR( test->startIdx, test->endIdx, gBuffer[3].in, gBuffer[1].in, gBuffer[2].in, test->optInTimePeriod, &outBegIdx, &outNbElement, gBuffer[3].in ); break; default: retCode = TA_BAD_PARAM; } /* Verify that the inputs were preserved. */ errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[3].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[3].in, 0 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { switch( test->id ) { case TST_MINUS_DM: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MINUS_DM, (void *)&testParam, 1, 0 ); break; case TST_MINUS_DI: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_MINUS_DI, (void *)&testParam, 1, 2 ); break; case TST_DX: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_DX, (void *)&testParam, 1, 2 ); break; case TST_ADX: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ADX, (void *)&testParam, 1, 2 ); break; case TST_PLUS_DM: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_PLUS_DM, (void *)&testParam, 1, 0 ); break; case TST_PLUS_DI: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_PLUS_DI, (void *)&testParam, 1, 2 ); break; case TST_ADXR: errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_ADX, (void *)&testParam, 1, 2 ); break; } if( errNb != TA_TEST_PASS ) return errNb; } return TA_TEST_PASS; }
static ErrorNumber do_test( const TA_History *history, const TA_Test *test ) { TA_RetCode retCode; ErrorNumber errNb; TA_Integer outBegIdx; TA_Integer outNbElement; TA_RangeTestParam testParam; /* Set to NAN all the elements of the gBuffers. */ clearAllBuffers(); /* Build the input. */ setInputBuffer( 0, history->high, history->nbBars ); setInputBuffer( 1, history->low, history->nbBars ); setInputBuffer( 2, history->close, history->nbBars ); /* Set the unstable period requested for that test. */ switch( test->optInSlowK_MAType_2 ) { case TA_MAType_EMA: retCode = TA_SetUnstablePeriod( TA_FUNC_UNST_EMA, test->unstablePeriod ); if( retCode != TA_SUCCESS ) return TA_TEST_TFRR_SETUNSTABLE_PERIOD_FAIL; break; default: /* No unstable period for other methods. */ break; } /* Make a simple first call. */ retCode = TA_STOCH( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInFastK_Period_0, test->optInSlowK_Period_1, test->optInSlowK_MAType_2, test->optInSlowD_Period_3, test->optInSlowD_MAType_4, &outBegIdx, &outNbElement, gBuffer[0].out0, gBuffer[0].out1 ); errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[0].out1, 1 ); outBegIdx = outNbElement = 0; /* Compare to the non-optimized version */ retCode = referenceStoch( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInFastK_Period_0, test->optInSlowK_Period_1, test->optInSlowK_MAType_2, test->optInSlowD_Period_3, test->optInSlowD_MAType_4, &outBegIdx, &outNbElement, gBuffer[1].out0, gBuffer[1].out1 ); errNb = checkDataSame( gBuffer[0].in, history->high,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[1].in, history->low, history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkDataSame( gBuffer[2].in, history->close,history->nbBars ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[1].out0, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].out1, 1 ); /* The non-optimized reference shall be identical to the optimzied TA-Lib * implementation. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[1].out0, gBuffer[0].out0 ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkSameContent( gBuffer[1].out1, gBuffer[0].out1 ); if( errNb != TA_TEST_PASS ) return errNb; /* Make another call where the input and the output are the * same buffer. */ retCode = TA_STOCH( test->startIdx, test->endIdx, gBuffer[0].in, gBuffer[1].in, gBuffer[2].in, test->optInFastK_Period_0, test->optInSlowK_Period_1, test->optInSlowK_MAType_2, test->optInSlowD_Period_3, test->optInSlowD_MAType_4, &outBegIdx, &outNbElement, gBuffer[0].in, gBuffer[1].in ); /* The previous call should have the same output as this call. * * checkSameContent verify that all value different than NAN in * the first parameter is identical in the second parameter. */ errNb = checkSameContent( gBuffer[0].out0, gBuffer[0].in ); if( errNb != TA_TEST_PASS ) return errNb; errNb = checkSameContent( gBuffer[0].out1, gBuffer[1].in ); if( errNb != TA_TEST_PASS ) return errNb; CHECK_EXPECTED_VALUE( gBuffer[0].in, 0 ); CHECK_EXPECTED_VALUE( gBuffer[1].in, 1 ); if( errNb != TA_TEST_PASS ) return errNb; /* Do a systematic test of most of the * possible startIdx/endIdx range. */ testParam.test = test; testParam.high = history->high; testParam.low = history->low; testParam.close = history->close; if( test->doRangeTestFlag ) { errNb = doRangeTest( rangeTestFunction, TA_FUNC_UNST_EMA, (void *)&testParam, 2, 0 ); if( errNb != TA_TEST_PASS ) return errNb; } /* Call a local non-optimized version of the function. * This way, we make sure that the currently speed optimized * version in TA-Lib is not broken. */ return TA_TEST_PASS; }