⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_abstract.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* TA-LIB Copyright (c) 1999-2007, Mario Fortier * All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following * conditions are met: * * - Redistributions of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * - Neither name of author nor the names of its contributors *   may be used to endorse or promote products derived from this *   software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *//* List of contributors: * *  Initial  Name/description *  ------------------------------------------------------------------- *  MF       Mario Fortier *  AC       Angelo Ciceri * * * Change history: * *  MMDDYY BY   Description *  ------------------------------------------------------------------- *  112703 MF   First version. *  030104 MF   Add tests for TA_GetLookback *  062504 MF   Add test_default_calls. *  110206 AC   Change volume and open interest to double *  082607 MF   Add profiling feature. *//* Description: *         Regression testing of the functionality provided *         by the ta_abstract module. * *         Also perform call to all functions for the purpose  *         of profiling (doExtensiveProfiling option). *//**** Headers ****/#ifdef WIN32   #include "windows.h"#else   #include "time.h"#endif#include <stdio.h>#include <string.h>#include <stdlib.h>#include <ctype.h>#include "ta_test_priv.h"/**** External functions declarations. ****//* None *//**** External variables declarations. ****/extern int doExtensiveProfiling;extern double gDataOpen[];extern double gDataHigh[];extern double gDataLow[];extern double gDataClose[];extern int nbProfiledCall;extern double timeInProfiledCall;extern double worstProfiledCall;extern int insufficientClockPrecision;/**** Global variables definitions.    ****//* None *//**** Local declarations.              ****/typedef enum {	PROFILING_10000,	PROFILING_8000,	PROFILING_5000,    PROFILING_2000,	PROFILING_1000,	PROFILING_500,	PROFILING_100} ProfilingType;/**** Local functions declarations.    ****/static ErrorNumber testLookback(TA_ParamHolder *paramHolder );static ErrorNumber test_default_calls(void);static ErrorNumber callWithDefaults( const char *funcName,									 const double *input,									 const int *input_int, int size );static ErrorNumber callAndProfile( const char *funcName, ProfilingType type );/**** Local variables definitions.     ****/static double inputNegData[100];static double inputZeroData[100];static double inputRandFltEpsilon[100];static double inputRandDblEpsilon[100];static double inputRandomData[2000];static int    inputNegData_int[100];static int    inputZeroData_int[100];static int    inputRandFltEpsilon_int[100];static int    inputRandDblEpsilon_int[100];static int    inputRandomData_int[2000];static double output[10][2000];static int    output_int[10][2000];/**** Global functions definitions.   ****/ErrorNumber test_abstract( void ){   ErrorNumber retValue;   TA_RetCode retCode;   TA_ParamHolder *paramHolder;   const TA_FuncHandle *handle;   int i;   const char *xmlArray;   printf( "Testing Abstract interface\n" );      retValue = allocLib();   if( retValue != TA_TEST_PASS )      return retValue;       /* Verify TA_GetLookback. */   retCode = TA_GetFuncHandle( "STOCH", &handle );   if( retCode != TA_SUCCESS )   {      printf( "Can't get the function handle [%d]\n", retCode );      return TA_ABS_TST_FAIL_GETFUNCHANDLE;      }                                retCode = TA_ParamHolderAlloc( handle, &paramHolder );   if( retCode != TA_SUCCESS )   {      printf( "Can't allocate the param holder [%d]\n", retCode );      return TA_ABS_TST_FAIL_PARAMHOLDERALLOC;   }   retValue = testLookback(paramHolder);   if( retValue != TA_SUCCESS )   {      printf( "testLookback() failed [%d]\n", retValue );      TA_ParamHolderFree( paramHolder );      return retValue;   }         retCode = TA_ParamHolderFree( paramHolder );   if( retCode != TA_SUCCESS )   {      printf( "TA_ParamHolderFree failed [%d]\n", retCode );      return TA_ABS_TST_FAIL_PARAMHOLDERFREE;   }   retValue = freeLib();   if( retValue != TA_TEST_PASS )      return retValue;   /* Call all the TA functions through the abstract interface. */   retValue = allocLib();   if( retValue != TA_TEST_PASS )      return retValue;   retValue = test_default_calls();   if( retValue != TA_TEST_PASS )   {      printf( "TA-Abstract default call failed\n" );      return retValue;   }   retValue = freeLib();   if( retValue != TA_TEST_PASS )      return retValue;      /* Verify that the TA_FunctionDescription is null terminated    * and as at least 500 characters (less is guaranteed bad...)    */   xmlArray = TA_FunctionDescriptionXML();   for( i=0; i < 1000000; i++ )   {      if( xmlArray[i] == 0x0 )         break;   }   if( i < 500)    {      printf( "TA_FunctionDescriptionXML failed. Size too small.\n" );      return TA_ABS_TST_FAIL_FUNCTION_DESC_SMALL;   }   if( i == 1000000 )   {      printf( "TA_FunctionDescriptionXML failed. Size too large (missing null?).\n" );      return TA_ABS_TST_FAIL_FUNCTION_DESC_LARGE;   }   return TA_TEST_PASS; /* Succcess. */}/**** Local functions definitions.     ****/static ErrorNumber testLookback( TA_ParamHolder *paramHolder ){  TA_RetCode retCode;  int lookback;  /* Change the parameters of STOCH and verify that TA_GetLookback respond correctly. */  retCode = TA_SetOptInputParamInteger( paramHolder, 0, 3 );  if( retCode != TA_SUCCESS )  {     printf( "TA_SetOptInputParamInteger call failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_OPTINPUTPARAMINTEGER;  }  retCode = TA_SetOptInputParamInteger( paramHolder, 1, 4 );  if( retCode != TA_SUCCESS )  {     printf( "TA_SetOptInputParamInteger call failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_OPTINPUTPARAMINTEGER;  }  retCode = TA_SetOptInputParamInteger( paramHolder, 2, (TA_Integer)TA_MAType_SMA );  if( retCode != TA_SUCCESS )  {     printf( "TA_SetOptInputParamInteger call failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_OPTINPUTPARAMINTEGER;  }  retCode = TA_SetOptInputParamInteger( paramHolder, 3, 4 );  if( retCode != TA_SUCCESS )  {     printf( "TA_SetOptInputParamInteger call failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_OPTINPUTPARAMINTEGER;  }  retCode = TA_SetOptInputParamInteger( paramHolder, 4, (TA_Integer)TA_MAType_SMA );  if( retCode != TA_SUCCESS )  {     printf( "TA_SetOptInputParamInteger call failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_OPTINPUTPARAMINTEGER;  }  retCode = TA_GetLookback(paramHolder,&lookback);  if( retCode != TA_SUCCESS )  {     printf( "TA_GetLookback failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_GETLOOKBACK_CALL_1;  }  if( lookback != 8 )  {     printf( "TA_GetLookback failed [%d != 8]\n", lookback );     return TA_ABS_TST_FAIL_GETLOOKBACK_1;  }  /* Change one parameter and check again. */  retCode = TA_SetOptInputParamInteger( paramHolder, 3, 3 );  if( retCode != TA_SUCCESS )  {     printf( "TA_SetOptInputParamInteger call failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_OPTINPUTPARAMINTEGER;  }  retCode = TA_GetLookback(paramHolder,&lookback);  if( retCode != TA_SUCCESS )  {     printf( "TA_GetLookback failed [%d]\n", retCode );     return TA_ABS_TST_FAIL_GETLOOKBACK_CALL_2;  }  if( lookback != 7 )  {     printf( "TA_GetLookback failed [%d != 7]\n", lookback );     return TA_ABS_TST_FAIL_GETLOOKBACK_2;  }    return TA_TEST_PASS;}static void testDefault( const TA_FuncInfo *funcInfo, void *opaqueData ){	static int nbFunctionDone = 0;   ErrorNumber *errorNumber;   errorNumber = (ErrorNumber *)opaqueData;   if( *errorNumber != TA_TEST_PASS )      return;#define CALL(x) { \	*errorNumber = callWithDefaults( funcInfo->name, x, x##_int, sizeof(x)/sizeof(double) ); \	if( *errorNumber != TA_TEST_PASS ) { \	   printf( "Failed for [%s][%s]\n", funcInfo->name, #x ); \       return; \	} \}   /* Do not test value outside the ]0..1[ domain for the "Math" groups. */   if( (strlen(funcInfo->group) < 4) || 	   !((tolower(funcInfo->group[0]) == 'm') && 	     (tolower(funcInfo->group[1]) == 'a') &&	     (tolower(funcInfo->group[2]) == 't') &&	     (tolower(funcInfo->group[3]) == 'h')))   {	         CALL( inputNegData );      CALL( inputZeroData );      CALL( inputRandFltEpsilon );      CALL( inputRandDblEpsilon );   }   CALL( inputRandomData );#undef CALL#define CALL(x) { \	*errorNumber = callAndProfile( funcInfo->name, x ); \	if( *errorNumber != TA_TEST_PASS ) { \	   printf( "Failed for [%s][%s]\n", funcInfo->name, #x ); \       return; \	} \}   if( doExtensiveProfiling /*&& (nbFunctionDone<5)*/ )   {	   nbFunctionDone++;	   printf( "%s ", funcInfo->name );       CALL( PROFILING_100 );       CALL( PROFILING_500 );	   CALL( PROFILING_1000 );       CALL( PROFILING_2000 );       CALL( PROFILING_5000 );       CALL( PROFILING_8000 );	   CALL( PROFILING_10000 );	   printf( "\n" );   }}static ErrorNumber callWithDefaults( const char *funcName, const double *input, const int *input_int, int size ){   TA_ParamHolder *paramHolder;   const TA_FuncHandle *handle;   const TA_FuncInfo *funcInfo;   const TA_InputParameterInfo *inputInfo;   const TA_OutputParameterInfo *outputInfo;   TA_RetCode retCode;   unsigned int i;   int j;   int outBegIdx, outNbElement, lookback;   retCode = TA_GetFuncHandle( funcName, &handle );   if( retCode != TA_SUCCESS )   {      printf( "Can't get the function handle [%d]\n", retCode );      return TA_ABS_TST_FAIL_GETFUNCHANDLE;      }                                retCode = TA_ParamHolderAlloc( handle, &paramHolder );   if( retCode != TA_SUCCESS )   {      printf( "Can't allocate the param holder [%d]\n", retCode );      return TA_ABS_TST_FAIL_PARAMHOLDERALLOC;   }   TA_GetFuncInfo( handle, &funcInfo );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -