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

📄 test_util.c

📁 股票主要技术指标源码
💻 C
📖 第 1 页 / 共 3 页
字号:
            {               printf( "Fail: doRangeTestFixSize out-of-bound output (%e)\n", outputBuffer[1+outputSizeByOptimalLogic] );               printf( "Fail: doRangeTestFixSize (%d,%d,%d,%d,%d)\n", startIdx, endIdx, outputBegIdx, outputNbElement, fixSize );               printf( "Fail: doRangeTestFixSize refOutBeg,refOutNbElement (%d,%d)\n", refOutBeg, refOutNbElement );               TA_Free( outputBuffer );               TA_Free( outputBufferInt );               return TA_TESTUTIL_DRT_OUT_OF_BOUND_OUT;            }            if( (fixSize != outputNbElement) && (outputBufferInt[1+outputSizeByOptimalLogic] != RESV_PATTERN_IMPROBABLE_INT) )            {               printf( "Fail: doRangeTestFixSize out-of-bound output  (%d)\n", outputBufferInt[1+outputSizeByOptimalLogic] );               printf( "Fail: doRangeTestFixSize (%d,%d,%d,%d,%d)\n", startIdx, endIdx, outputBegIdx, outputNbElement, fixSize );               printf( "Fail: doRangeTestFixSize refOutBeg,refOutNbElement (%d,%d)\n", refOutBeg, refOutNbElement );               TA_Free( outputBuffer );               TA_Free( outputBufferInt );               return TA_TESTUTIL_DRT_OUT_OF_BOUND_OUT_INT;            }            /* Verify that the memory guard were preserved. */            if( outputBuffer[0] != RESV_PATTERN_PREFIX )            {               printf( "Fail: doRangeTestFixSize bad RESV_PATTERN_PREFIX (%e)\n", outputBuffer[0] );               printf( "Fail: doRangeTestFixSize (%d,%d,%d,%d,%d)\n", startIdx, endIdx, outputBegIdx, outputNbElement, fixSize );               printf( "Fail: doRangeTestFixSize refOutBeg,refOutNbElement (%d,%d)\n", refOutBeg, refOutNbElement );               TA_Free( outputBuffer );               TA_Free( outputBufferInt );               return TA_TESTUTIL_DRT_BAD_PREFIX;            }            if( outputBufferInt[0] != RESV_PATTERN_PREFIX_INT )            {               printf( "Fail: doRangeTestFixSize bad RESV_PATTERN_PREFIX_INT (%d)\n", outputBufferInt[0] );               printf( "Fail: doRangeTestFixSize (%d,%d,%d,%d,%d)\n", startIdx, endIdx, outputBegIdx, outputNbElement, fixSize );               printf( "Fail: doRangeTestFixSize refOutBeg,refOutNbElement (%d,%d)\n", refOutBeg, refOutNbElement );               TA_Free( outputBuffer );               TA_Free( outputBufferInt );               return TA_TESTUTIL_DRT_BAD_PREFIX;            }            if( outputBuffer[fixSize+1] != RESV_PATTERN_SUFFIX )            {               printf( "Fail: doRangeTestFixSize bad RESV_PATTERN_SUFFIX (%e)\n", outputBuffer[fixSize+1] );               printf( "Fail: doRangeTestFixSize (%d,%d,%d,%d,%d)\n", startIdx, endIdx, outputBegIdx, outputNbElement, fixSize );               printf( "Fail: doRangeTestFixSize refOutBeg,refOutNbElement (%d,%d)\n", refOutBeg, refOutNbElement );               TA_Free( outputBuffer );               TA_Free( outputBufferInt );               return TA_TESTUTIL_DRT_BAD_SUFFIX;            }            if( outputBufferInt[fixSize+1] != RESV_PATTERN_SUFFIX_INT )            {               printf( "Fail: doRangeTestFixSize bad RESV_PATTERN_SUFFIX_INT (%d)\n", outputBufferInt[fixSize+1] );               printf( "Fail: doRangeTestFixSize (%d,%d,%d,%d,%d)\n", startIdx, endIdx, outputBegIdx, outputNbElement, fixSize );               printf( "Fail: doRangeTestFixSize refOutBeg,refOutNbElement (%d,%d)\n", refOutBeg, refOutNbElement );               TA_Free( outputBuffer );               TA_Free( outputBufferInt );               return TA_TESTUTIL_DRT_BAD_SUFFIX;            }            /* Clean-up for next test. */            if( outputIsInteger )            {               for( i=1; i <= fixSize; i++ )                  outputBufferInt[i] = RESV_PATTERN_IMPROBABLE_INT;            }            else            {               for( i=1; i <= fixSize; i++ )                  outputBuffer[i] = RESV_PATTERN_IMPROBABLE;            }         }         /* Skip some startIdx at random. Limit case are still           * tested though.          */         if( (startIdx > 30) && ((startIdx+100) <= (MAX_RANGE_SIZE-fixSize)) )                      {            /* Randomly skips from 40 to 100 tests. */            temp = (rand() % 100)+40;            startIdx += temp;         }      }      /* Loop and move forward for the next startIdx to test. */   }   TA_Free( outputBuffer );   TA_Free( outputBufferInt );   return TA_TEST_PASS;}/* This function compares two value. * The value is determined to be equal * if it is within a certain error range. */static int dataWithinReasonableRange( TA_Real val1, TA_Real val2,                                      unsigned int outputPosition,                                      TA_FuncUnstId unstId,                                      unsigned int integerTolerance ){   TA_Real difference, tolerance, temp;   unsigned int val1_int, val2_int, tempInt, periodToIgnore;   if( integerTolerance == TA_DO_NOT_COMPARE )      return 1; /* Don't compare, says that everything is fine */   /* If the function does not have an unstable period,    * the compared value shall be identical.    *    * Because the algo may vary slightly allow for    * a small epsilon error because of the nature    * of floating point operations.    */   if( unstId == TA_FUNC_UNST_NONE )      return TA_REAL_EQ( val1, val2, 0.000000001 );   /* In the context of the TA functions, all value    * below 0.00001 are considered equal to zero and    * are considered to be equal within a reasonable range.    * (the percentage difference might be large, but    *  unsignificant at that level, so no tolerance    *  check is being done).    */    if( (val1 < 0.00001) && (val2 < 0.00001) )      return 1;   /* When the function is unstable, the comparison    * tolerate at first a large difference.    *    * As the number of "outputPosition" is higher    * the tolerance is reduced.    *    * In the same way, as the unstable period    * increase, the tolerance is reduced (that's    * what the unstable period is for... reducing    * difference).    *    * When dealing with an unstable period, the    * first 100 values are ignored.    *    * Following 100, the tolerance is     * progressively reduced as follow:    *    *   1   == 0.5/1   == 50  %    *   2   == 0.5/2   == 25  %    *   ...    *   100 == 0.5/100 == 0.005 %    *   ...    *    * Overall, the following is a fair estimation:    *  When using a unstable period of 200, you    *  can expect the output to not vary more    *  than 0.005 %    *    * The logic is sligthly different if the     * output are rounded integer, but it is    * the same idea.    *    * The following describe the special meaning of    * the integerTolerance:    *    * Value 10      -> A tolerance of 1/10  is used.    *    * Value 100     -> A tolerance of 1/100 is used.    *    * Value 1000    -> A tolerance of 1/1000 is used.    *     * Value 360     -> Useful when the output are    *                  degrees. In that case, a fix    *                  tolerance of 1 degree is used.    *    * Value TA_DO_NOT_COMPARE ->     *                  Indicate that NO COMPARISON take    *                  place. This is useful for functions    *                  that cannot be compare when changing    *                  the range (like the accumulative    *                  algorithm used for TA_AD and TA_ADOSC).    */   /* Some functions requires a longer unstable period.    * These are trap here.    */   switch( unstId )   {   case TA_FUNC_UNST_T3:      periodToIgnore = 200;      break;   default:      periodToIgnore = 100;      break;   }   if( integerTolerance == 1000 )   {      /* Check for no difference of more       * than 1/1000       */      if( val1 > val2 )         difference = (val1-val2);      else         difference = (val2-val1);      difference *= 1000.0;      temp = outputPosition+TA_GetUnstablePeriod(unstId)+1;      if( temp <= periodToIgnore )      {         /* Pretend it is fine. */         return 1;      }      else if( (int)difference > 1 )      {         printf( "\nFail: Value diffferent by more than 1/1000 (%f)\n", difference );         return 0;      }   }   else if( integerTolerance == 100 )   {      /* Check for no difference of more       * than 1/1000       */      if( val1 > val2 )         difference = (val1-val2);      else         difference = (val2-val1);      difference *= 100.0;      temp = outputPosition+TA_GetUnstablePeriod(unstId)+1;      if( temp <= periodToIgnore )      {         /* Pretend it is fine. */         return 1;      }      else if( (int)difference > 1 )      {         printf( "\nFail: Value diffferent by more than 1/100 (%f)\n", difference );         return 0;      }   }   else if( integerTolerance == 10 )   {      /* Check for no difference of more       * than 1/1000       */      if( val1 > val2 )         difference = (val1-val2);      else         difference = (val2-val1);      difference *= 10.0;      temp = outputPosition+TA_GetUnstablePeriod(unstId)+1;      if( temp <= periodToIgnore )      {         /* Pretend it is fine. */         return 1;      }      else if( (int)difference > 1 )      {         printf( "\nFail: Value diffferent by more than 1/10 (%f)\n", difference );         return 0;      }   }   else if( integerTolerance == 360 )   {      /* Check for no difference of no more       * than 10% when the value is higher than       * 1 degree.       *       * Difference of less than 1 degree are not significant.       */      val1_int = (unsigned int)val1;      val2_int = (unsigned int)val2;      if( val1_int > val2_int )         tempInt = val1_int - val2_int;      else         tempInt = val2_int - val1_int;      if( val1 > val2 )         difference = (val1-val2)/val1;      else         difference = (val2-val1)/val2;      temp = outputPosition+TA_GetUnstablePeriod(unstId)+1;      if( temp <= periodToIgnore )      {         /* Pretend it is fine. */         return 1;      }      else if( (tempInt > 1) && (difference > 0.10) )      {         printf( "\nFail: Value diffferent by more than 10 percent over 1 degree (%d)\n", tempInt );         return 0;      }          }   else if( integerTolerance )   {      /* Check that the integer part of the value       * is not different more than the specified       * integerTolerance.       */      val1_int = (unsigned int)val1;      val2_int = (unsigned int)val2;      if( val1_int > val2_int )         tempInt = val1_int - val2_int;      else         tempInt = val2_int - val1_int;      temp = outputPosition+TA_GetUnstablePeriod(unstId)+1;      if( temp <= periodToIgnore )      {         /* Pretend it is fine. */         return 1;      }      else if( temp < 100 )      {         if( tempInt >= 3*integerTolerance )         {            printf( "\nFail: Value out of 3*tolerance range (%d,%d)\n", tempInt, integerTolerance );            return 0; /* Value considered different */         }      }      else if( temp < 150 )      {         if( tempInt >= 2*integerTolerance )         {            printf( "\nFail: Value out of 2*tolerance range (%d,%d)\n", tempInt, integerTolerance );            return 0; /* Value considered different */         }      }      else if( temp < 200 )      {         if( tempInt >= integerTolerance )         {            printf( "\nFail: Value out of tolerance range (%d,%d)\n", tempInt, integerTolerance );            return 0; /* Value considered different */         }      }      else if( tempInt >= 1 )      {         printf( "\nFail: Value not equal (difference is %d)\n", tempInt );         return 0; /* Value considered different */      }    }   else   {      if( val1 > val2 )         difference = (val1-val2)/val1;      else         difference = (val2-val1)/val2;           temp = outputPosition+TA_GetUnstablePeriod(unstId)+1;      if( temp <= periodToIgnore )      {         /* Pretend it is fine. */         return 1;      }      else      {         temp -= periodToIgnore;         tolerance = 0.5/temp;      }       if( difference > tolerance )      {         printf( "\nFail: Value out of tolerance range (%g,%g)\n", difference, tolerance );         return 0; /* Out of tolerance... values are not equal. */      }   }   return 1; /* Value equal within tolerance. */}static TA_RetCode CallTestFunction( RangeTestFunction testFunction,                                    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 ){   /* Call the function and do profiling. */   TA_RetCode retCode;   double clockDelta;#ifdef WIN32   LARGE_INTEGER startClock;   LARGE_INTEGER endClock;#else   clock_t startClock;   clock_t endClock;#endif#ifdef WIN32   QueryPerformanceCounter(&startClock);#else   startClock = clock();#endif	retCode = testFunction( startIdx,                  endIdx,                  outputBuffer,                  outputBufferInt,                  outBegIdx,                  outNbElement,                  lookback,                  opaqueData,                  outputNb,                  isOutputInteger );   	/* Profile only functions producing at least 20 values. */	if( *outNbElement < 20 )	{		return retCode;	}#ifdef WIN32   QueryPerformanceCounter(&endClock);   clockDelta = (double)((__int64)endClock.QuadPart - (__int64) startClock.QuadPart);#else   endClock = clock();   clockDelta = (double)(endClock - startClock);#endif   if( clockDelta <= 0 )   {	   insufficientClockPrecision = 1;	      }   else   {	         if( clockDelta > worstProfiledCall )         worstProfiledCall = clockDelta;      timeInProfiledCall += clockDelta;      nbProfiledCall++;   }      return retCode;}

⌨️ 快捷键说明

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