📄 test_candlestick.c
字号:
/* Verify that there is only one output. */ if( funcInfo->nbOutput != 1 ) { printf( "Candlestick are expected to have only one output array.\n" ); return TA_TSTCDL_NBOUTPUT_WRONG; } TA_GetOutputParameterInfo( handle, 0, &outputInfo ); if( outputInfo->type != TA_Output_Integer ) { printf( "Candlestick are expected to have only one output array of type integer.\n" ); return TA_TSTCDL_OUTPUT_TYPE_WRONG; } /* !!!!!!!!!!!!! TO BE DONE !!!!!!!!!!!!!!!!!! * For now all candlestick functions will be called with default optional parameter. */ } /* Set the input buffers. */ TA_SetInputParamPricePtr( paramHolder, 0, inOpen, inHigh, inLow, inClose, NULL, NULL ); TA_SetOutputParamIntegerPtr(paramHolder,0,outInteger); /* Do the function call. */ *taFuncRetCode = TA_CallFunc(paramHolder,startIdx,endIdx,outBegIdx,outNbElement); if( *taFuncRetCode != TA_SUCCESS ) { printf( "TA_CallFunc() failed [%d]\n", *taFuncRetCode ); TA_ParamHolderFree( paramHolder ); return TA_TSTCDL_CALLFUNC_FAIL; } /* Do the lookback function call. */ retCode = TA_GetLookback( paramHolder, lookback ); if( retCode != TA_SUCCESS ) { printf( "TA_GetLookback() failed [%d]\n", retCode ); TA_ParamHolderFree( paramHolder ); return TA_TSTCDL_GETLOOKBACK_FAIL; } return TA_TEST_PASS; }/* rangeTestFunction is a different way to call any of * the TA function. * * This is called by doRangeTest found in test_util.c * * The doRangeTest verifies behavior that should be common * for ALL TA functions. It detects bugs like: * - outBegIdx, outNbElement and lookback inconsistency. * - off-by-one writes to output. * - output inconsistency for different start/end index. * - ... many other limit cases... * * In the case of candlestick, the output is integer and * should be put in outputBufferInt, and outputBuffer is * ignored. */static TA_RetCode rangeTestFunction( TA_Integer startIdx, TA_Integer endIdx, TA_Real *outputBuffer, TA_Integer *outputBufferInt, TA_Integer *outBegIdx, TA_Integer *outNbElement, TA_Integer *lookback, void *opaqueData, unsigned int outputNb, unsigned int *isOutputInteger ){ TA_RangeTestParam *testParam1; const TA_Test *testParam2; ErrorNumber errNb; TA_RetCode retCode; (void)outputBuffer; (void)outputNb; testParam1 = (TA_RangeTestParam *)opaqueData; testParam2 = (const TA_Test *)testParam1->test; *isOutputInteger = 1; /* Must be != 0 */ retCode = TA_INTERNAL_ERROR(166); /* Call the TA function by name */ errNb = callCandlestick( &testParam1->paramHolder, testParam2->name, startIdx, endIdx, testParam1->open, testParam1->high, testParam1->low, testParam1->close, testParam2->params, outBegIdx, outNbElement, outputBufferInt, lookback, &retCode ); if( errNb != TA_TEST_PASS ) retCode = TA_INTERNAL_ERROR(168); return retCode;}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;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -