Пример #1
0
/// @file unit_tests/unit_main.cpp
/// @brief provide a main function for the unit test harness
/// 
///         takes 2 or 3 command line arguments:
///             1st is output file for unit test case failure results
///             2nd is output file for unit test errors
///             3rd is input file utilized if tested function takes input
///                 input file is optional command line arg
///         You shouldn't have to edit this file at all
int main(int argc, char **argv)
{
    std::string function_to_test;
    std::ofstream harnessOutput;
    std::ofstream harnessError;
    if(argc == 3 || argc == 4)
    {
        harnessOutput.open(argv[1]);
        harnessError.open(argv[2]);
    }
    else 
    {
        std::cerr << "Incorrect number of command line args" << std::endl;
        return 1;
    }

    if (argc == 4)
        testFunction(harnessOutput, harnessError, argv[3]);        
    else
        testFunction(harnessOutput, harnessError);
    
    harnessOutput.close();
    harnessError.close();
    return 0;
}
void TestParseFunctions::testParsing()
{
    testFunction("-5*x", 3, -15);
    testFunction("2+5", 0, 7);
    testFunction("X*2-9", 1, -7);
    testFunction("2^3+3", 0, 11);
    testFunction("x/(1+x*x)", 0, 0);
    testFunction("1/(1+x*x)", 0, 1);
    testFunction("exp(-(x*x))", 0, 1);
    testFunction("10*exp(-(x*x))", 0, 10);
    testFunction("x^2", 2, 4);
}
Пример #3
0
int main(void)
{
   int i;

   // clang-tidy should insert braces in the below for loop. clang-format should removed the spaces above, and move the
   // braces clang-tidy adds below to the following line and re-indent them. Clang-formatting should fix all of the
   // indentation in this function.
   for (i = 0; i < 3; i++)
      printf("Hello World!\n");

   // clang-tidy should replace both of these instances with nullptr.
   testFunction(NULL);
   testFunction(0);

   return 0;
}
Пример #4
0
  double evaluateSample( const vectord &Xi ) 
  {
    double x[100];
    for (size_t i = 0; i < Xi.size(); ++i)
	x[i] = Xi(i);
    return testFunction(Xi.size(),x,NULL,NULL);
  };
Пример #5
0
int doTest(const char *testName,
           int (*testFunction) (), int points, int *score, int *totalTests,
           int *successfulTests) {
    int ret;

    (*totalTests)++;

    Print("Testing: %s...", testName);

    ret = testFunction();

    if (ret < 0) {
        Print("FAILED (%d)", ret);
        if (fail_immediately) {
            Exit(-1);
        }
    } else {
        Print("PASSED (%d)", ret);
        (*score) += points;
        (*successfulTests)++;
    }

    Print(" crt score: %d \n", (*score));

    return ret;

}
Пример #6
0
TestConfiguration *QuickTestTreeItem::testConfiguration() const
{
    ProjectExplorer::Project *project = ProjectExplorer::SessionManager::startupProject();
    QTC_ASSERT(project, return 0);

    QuickTestConfiguration *config = 0;
    switch (type()) {
    case TestCase: {
        QStringList testFunctions;
        for (int row = 0, count = childCount(); row < count; ++row)
            testFunctions << name() + QLatin1String("::") + childItem(row)->name();
        config = new QuickTestConfiguration;
        config->setTestCases(testFunctions);
        config->setProFile(proFile());
        config->setProject(project);
        break;
    }
    case TestFunctionOrSet: {
        TestTreeItem *parent = parentItem();
        QStringList testFunction(parent->name() + QLatin1String("::") + name());
        config = new QuickTestConfiguration;
        config->setTestCases(testFunction);
        config->setProFile(parent->proFile());
        config->setProject(project);
        break;
    }
    default:
        return 0;
    }
    return config;
}
Пример #7
0
int main()
{
	int random_data[DATA_LEN];

	testFunction(random_data, DATA_LEN);

	return 0;
}
Пример #8
0
void
 test_a_f64_z_i64_rx(
     int_fast64_t trueFunction( float64_t, int_fast8_t, bool ),
     int_fast64_t testFunction( float64_t, int_fast8_t, bool ),
     int_fast8_t roundingMode,
     bool exact
 )
{
    int count;
    int_fast64_t trueZ;
    int_fast8_t trueFlags;
    int_fast64_t testZ;
    int_fast8_t testFlags;

    genCases_f64_a_init();
    genCases_writeTestsTotal( testLoops_forever );
    verCases_errorCount = 0;
    verCases_tenThousandsCount = 0;
    count = 10000;
    while ( ! genCases_done || testLoops_forever ) {
        genCases_f64_a_next();
        *testLoops_trueFlagsPtr = 0;
        trueZ = trueFunction( genCases_f64_a, roundingMode, exact );
        trueFlags = *testLoops_trueFlagsPtr;
        testLoops_testFlagsFunction();
        testZ = testFunction( genCases_f64_a, roundingMode, exact );
        testFlags = testLoops_testFlagsFunction();
        --count;
        if ( ! count ) {
            verCases_perTenThousand();
            count = 10000;
        }
        if ( ( trueZ != testZ ) || ( trueFlags != testFlags ) ) {
            if (
                ! verCases_checkNaNs && f64_isSignalingNaN( genCases_f64_a )
            ) {
                trueFlags |= softfloat_flag_invalid;
            }
            if (
                   ( trueZ != INT64_C( 0x7FFFFFFFFFFFFFFF ) )
                || (    ( testZ != INT64_C( 0x7FFFFFFFFFFFFFFF ) )
                     && ( testZ != - INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1 ) )
                || ( trueFlags != softfloat_flag_invalid )
                || ( testFlags != softfloat_flag_invalid )
            ) {
                ++verCases_errorCount;
                verCases_writeErrorFound( 10000 - count );
                writeCase_a_f64( genCases_f64_a, "  " );
                writeCase_z_i64( trueZ, trueFlags, testZ, testFlags );
                if ( verCases_errorCount == verCases_maxErrorCount ) break;
            }
        }
    }
    verCases_writeTestsPerformed( 10000 - count );

}
Пример #9
0
int main(int argc, char **argv) {
    voidVoid block = testFunction();
    dirtyStack();
    block();
    Block_release(block);

    printf("%s: success\n", argv[0]);

    return 0;
}
Пример #10
0
struct test_search_struct {
  int test_a;
  int test_b;
}

int main(void) {
  testFunction();
  puts("Hellow World!");
  return EXIT_SUCCESS;
}
Пример #11
0
void crest_use()
{
  int i;
  int* ptr;
  unsigned int id;
  
  for(i=0;i<Num;i++)
  {
    if(_crest_arr[i]){
		id = _crest_arr[i]->inj_id;
		ptr = _crest_arr[i]->crest_ptr;
	  if(is_all_use_id(id))
		  testFunction(ptr);
	  else if(inj_histgram[id]%2==1){
		  testFunction(ptr);
	  }
	  inj_histgram[id]++;
	  
	}
  }
}
Пример #12
0
void
 test_a_i32_z_f32(
     float32_t trueFunction( int_fast32_t ),
     float32_t testFunction( int_fast32_t )
 )
{
    int count;
    float32_t trueZ;
    int_fast8_t trueFlags;
    float32_t testZ;
    int_fast8_t testFlags;

    genCases_i32_a_init();
    genCases_writeTestsTotal( testLoops_forever );
    verCases_errorCount = 0;
    verCases_tenThousandsCount = 0;
    count = 10000;
    while ( ! genCases_done || testLoops_forever ) {
        genCases_i32_a_next();
        *testLoops_trueFlagsPtr = 0;
        trueZ = trueFunction( genCases_i32_a );
        trueFlags = *testLoops_trueFlagsPtr;
        testLoops_testFlagsFunction();
        testZ = testFunction( genCases_i32_a );
        testFlags = testLoops_testFlagsFunction();
        --count;
        if ( ! count ) {
            verCases_perTenThousand();
            count = 10000;
        }
        if ( ! f32_same( trueZ, testZ ) || ( trueFlags != testFlags ) ) {
            if (
                   verCases_checkNaNs
                || ! f32_isNaN( trueZ )
                || ! f32_isNaN( testZ )
                || f32_isSignalingNaN( testZ )
                || ( trueFlags != testFlags )
            ) {
                ++verCases_errorCount;
                verCases_writeErrorFound( 10000 - count );
                writeCase_a_i32( genCases_i32_a, "  " );
                writeCase_z_f32( trueZ, trueFlags, testZ, testFlags );
                if ( verCases_errorCount == verCases_maxErrorCount ) break;
            }
        }
    }
    verCases_writeTestsPerformed( 10000 - count );

}
Пример #13
0
bool forall(const E & collection, const F & testFunction) {

	const auto startI = collection.begin();
	const auto endI = collection.end();

	auto i = startI;
	while (i != endI) {
		if (!testFunction(*i)) {
			return false;
		}

		i++;
	}

	return true;
}
Пример #14
0
PyObject *MyCommand(PyObject *self, PyObject *args)
{
  PyObject *result = NULL;
  long a, b;

  if (PyArg_ParseTuple(args, "ii", &a, &b)) {
    result = Py_BuildValue("i", a + b);
  } /* otherwise there is an error,
     * the exception already raised by PyArg_ParseTuple, and NULL is
     * returned.
     */

  //Call something interesting
  testFunction(5);

  return result;
}
Пример #15
0
void main()
{
      int localData;     /* 自動変数 */
  static int staticData;    /* 静的変数 */
      int *heapData;    /* ポインタ変数 */

  /**
   * ポインタ変数に対して、メモリを割り当てる
   */
  heapData = (int *) malloc( sizeof(int) );

  /**
   * 各変数のアドレスを出力する
   */
  printf(" gaibuData:%08X\n localData:%08X\n staticData:%08X\n heapData:%08X\n"
      " testFunction:%08X\n main:%08X\n printf:%08X\n", 
      &gaibuData, &localData, &staticData, heapData,
      testFunction, main, printf);

  testFunction();
}
Пример #16
0
//--------------------------------------------------------------
void testApp::setup(){
    
    int tmp = 5;
    int *myPtr = &tmp;  // Assign the address of tmp to our pointer.  They now have the same address in memory.
    int val = *myPtr;   // This is saying that we want to copy the value of myPtr (since we dereferenced it). Not the same address in memory!
    
    // & is known as the reference operator
    
    
    cout << "The address of tmp is " << &tmp << endl;
    cout << "The address of myPtr is " << myPtr << " / " << (*myPtr) << endl;       // display the address, then dereference it to get the value
    cout << "The address of val is " << &val << " / " << val << endl;
    
    cout << "------" << endl;
    
    // Now assign 8 to tmp. Since tmp and myPtr point to the same address in memory, both change!
    // When we assigned val however, we copied the value, not the address.  It's value remains unchanged.
    tmp = 8;
    
    cout << "The address of tmp is " << &tmp << endl;
    cout << "The address of myPtr is " << myPtr << " / " << (*myPtr) << endl;
    cout << "The address of val is " << &val << " / " << val << endl;
    
    cout << "------" << endl;

    // Reassign the address of myPtr so now it's pointing to the same thing as val
    // Both val and myPtr should now be 5! (tmp will still be 8)
    myPtr = &val;
    
    cout << "The address of tmp is " << &tmp << endl;
    cout << "The address of myPtr is " << myPtr << " / " << (*myPtr) << endl;
    cout << "The address of val is " << &val << " / " << val << endl;
    
    testFunction( tmp );
    
    
    // this is how you make memory leaks
//    int *leaky = new int;
//    leaky = &tmp;
}
Пример #17
0
int main(void)
{
    gitTrailApp* self;

    self = gitTrailApp_Create();
    if(self == NULL){
        printf("Create Failed\n");
        return 1;
    }

    printf("Create OK\n");

    printf("Test\n");

    printf("HogeHoge\n");
    
    testFunction();
     
    gitTrailApp_Delete(self);
    printf("Delete OK\n");

    return 0;
}
Пример #18
0
main ()

{
Id	c, sc;
int	i;
TEXT	name[STRINGSIZ+1];
CODE	testFunction(), deleteFunction ();
int	*ip;
CODE	display ();
CODE	Vm_Free ();
CODE 	writeSingleFile ();
struct VARIABLE	*v;

c =  Co_New (0);
for (i=0; i < 10; i++)
    {
    ip = (int *) tae_alloc (1, sizeof (int));	/* each obj is an int */
    *ip = i;					/* value of obj  */
    sprintf (name, "%d", i);			/* make a name	 */
    Co_Add (c, ip, name, i);			/* let type == i */
    }
Co_ForEach (c, (coFunction)testFunction, "proper context");
ip = Co_Find (c, "5");
if (*ip != 5) printf ("\n***********error in Co_Find call\n\n");
Co_Free (c, deleteFunction);

/*	start again and test remove */

c = Co_New (0);
for (i=0; i < 10; i++)
    {
    ip = (int *) tae_alloc (1, sizeof (int));	/* each obj is an int */
    *ip = i;					/* value of obj  */
    sprintf (name, "%d", i);			/* make a name	 */
    Co_Add (c, ip, name, i);			/* let type == i */
    }
ip = (int *) Co_Remove (c, "0");
tae_free (ip);
ip = (int *) Co_Remove (c, "5");
tae_free (ip);
ip = (int *) Co_Remove (c, "9");
tae_free (ip);
Co_ForEach (c, (coFunction)testFunction, "0, 5, and 9 missing?");
Co_Free (c, deleteFunction);
printf ("\n\n********** remember to check dm_bytes zero here *********\n");

/*	vm read and write	*/

    c = Co_New (0);
    Co_ReadFile (c, "test", P_ABORT) ;		/* read concatenated file */
    Co_ForEach (c, (coFunction)display, NULL);		/* show variable names	  */
    Co_ForEach (c, (coFunction)writeSingleFile, NULL);	/* write individual files */
    Co_WriteFile (c, "newtest") ;		/* wirte one concat file  */
    Co_Free (c, Vm_Free);
    printf ("\n\n********** remember to check dm_bytes zero here *********\n");

/*	test collections of collections	*/

c =  Co_New (0);
for (i=0; i < 10; i++)
    {
    ip = (int *) tae_alloc (1, sizeof (int));	/* each obj is an int */
    *ip = i;					/* value of obj  */
    sprintf (name, "%d", i);			/* make a name	 */
    Co_Add (c, ip, name, i);			/* let type == i */
    }
sc = Co_New (0);				/* super collection       */
Co_Add (sc, c, "subc1", C_COLLECTION);		/* with 4 sub-collections */
Co_Add (sc, c, "subc2", C_COLLECTION);
Co_Add (sc, c, "subc3", C_COLLECTION);
Co_Add (sc, c, "subc4", C_COLLECTION);

/*	do some composite lookups	*/

ip = (int *) Co_Find (sc, "subc1.5");
printf ("should be a 5: %d\n", *ip);
ip = (int *) Co_Find (sc, "subc2.1");
printf ("should be a 1: %d\n", *ip);
Co_Free (c, deleteFunction);
Co_Free (sc, NULL);
printf ("\n\n********** remember to check dm_bytes zero here *********\n");

/*	check composite Co_Find with Vm objects		*/

c = Co_New (0);
Co_ReadFile (c, "test", P_ABORT) ;		/* read concatenated file */
v = (struct VARIABLE *) Co_Find (c, "pp_target.p2");
printf ("variable P2 in block pp_target: %s\n", SVAL(*v,0));
v = (struct VARIABLE *) Co_Find (c, "pp_view._panel.origin");
printf ("variable _panel.origin in block pp_view: %d  %d \n", 
					      IVAL(*v,0), IVAL(*v,1));
Co_Free (c, Vm_Free);
printf ("\n\n********** remember to check dm_bytes zero here *********\n");

}
int main( int argc, char *argv[] )
{
    bool haveFunctionArg;
    const struct standardFunctionInfo *standardFunctionInfoPtr;
    int numOperands;
    uint_fast8_t roundingPrecision;
    int roundingCode;
    const char *argPtr;
    void (*const *subjFunctionPtrPtr)();
    const char *functionNamePtr;
    long i;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    fail_programName = "testfloat";
    if ( argc <= 1 ) goto writeHelpMessage;
    genCases_setLevel( 1 );
    verCases_maxErrorCount = 20;
    testLoops_trueFlagsPtr = &softfloat_exceptionFlags;
    testLoops_subjFlagsFunction = subjfloat_clearExceptionFlags;
    haveFunctionArg = false;
    standardFunctionInfoPtr = 0;
    numOperands = 0;
    roundingPrecision = 0;
    roundingCode = 0;
    for (;;) {
        --argc;
        if ( ! argc ) break;
        argPtr = *++argv;
        if ( ! argPtr ) break;
        if ( argPtr[0] == '-' ) ++argPtr;
        if (
            ! strcmp( argPtr, "help" ) || ! strcmp( argPtr, "-help" )
                || ! strcmp( argPtr, "h" )
        ) {
 writeHelpMessage:
            fputs(
"testfloat [<option>...] <function>\n"
"  <option>:  (* is default)\n"
"    -help            --Write this message and exit.\n"
"    -list            --List all testable subject functions and exit.\n"
"    -level <num>     --Testing level <num> (1 or 2).\n"
" *  -level 1\n"
"    -errors <num>    --Stop each function test after <num> errors.\n"
" *  -errors 20\n"
"    -errorstop       --Exit after first function with any error.\n"
"    -forever         --Test one function repeatedly (implies `-level 2').\n"
"    -checkNaNs       --Check for bitwise correctness of NaN results.\n"
#ifdef EXTFLOAT80
"    -precision32     --For extF80, test only 32-bit rounding precision.\n"
"    -precision64     --For extF80, test only 64-bit rounding precision.\n"
"    -precision80     --For extF80, test only 80-bit rounding precision.\n"
#endif
"    -r<round>        --Test only specified rounding (if not inherent to\n"
"                         function).\n"
"    -tininessbefore  --Underflow tininess is detected before rounding.\n"
"    -tininessafter   --Underflow tininess is detected after rounding.\n"
"  <function>:\n"
"    <int>_to_<float>               <float>_add      <float>_eq\n"
"    <float>_to_<int>_r_<round>     <float>_sub      <float>_le\n"
"    <float>_to_<int>_rx_<round>    <float>_mul      <float>_lt\n"
"    <float>_to_<float>             <float>_mulAdd   <float>_eq_signaling\n"
"    <float>_roundToInt_r_<round>   <float>_div      <float>_le_quiet\n"
"    <float>_roundToInt_x           <float>_rem      <float>_lt_quiet\n"
"                                   <float>_sqrt\n"
"    -all1            --All unary functions.\n"
"    -all2            --All binary functions.\n"
"  <int>:\n"
"    ui32             --Unsigned 32-bit integer.\n"
"    ui64             --Unsigned 64-bit integer.\n"
"    i32              --Signed 32-bit integer.\n"
"    i64              --Signed 64-bit integer.\n"
"  <float>:\n"
"    f32              --Binary 32-bit floating-point (single-precision).\n"
"    f64              --Binary 64-bit floating-point (double-precision).\n"
#ifdef EXTFLOAT80
"    extF80           --Binary 80-bit extended floating-point.\n"
#endif
#ifdef FLOAT128
"    f128             --Binary 128-bit floating-point (quadruple-precision).\n"
#endif
"  <round>:\n"
"    near_even        --Round to nearest/even.\n"
"    minMag           --Round to minimum magnitude (toward zero).\n"
"    min              --Round to minimum (down).\n"
"    max              --Round to maximum (up).\n"
"    near_maxMag      --Round to nearest/maximum magnitude (nearest/away).\n"
                ,
                stdout
            );
            return EXIT_SUCCESS;
        } else if ( ! strcmp( argPtr, "list" ) ) {
            standardFunctionInfoPtr = standardFunctionInfos;
            subjFunctionPtrPtr = subjfloat_functions;
            for (;;) {
                functionNamePtr = standardFunctionInfoPtr->namePtr;
                if ( ! functionNamePtr ) break;
                if ( *subjFunctionPtrPtr ) puts( functionNamePtr );
                ++standardFunctionInfoPtr;
                ++subjFunctionPtrPtr;
            }
            return EXIT_SUCCESS;
        } else if ( ! strcmp( argPtr, "level" ) ) {
            if ( argc < 2 ) goto optionError;
            i = strtol( argv[1], (char **) &argPtr, 10 );
            if ( *argPtr ) goto optionError;
            genCases_setLevel( i );
            --argc;
            ++argv;
        } else if ( ! strcmp( argPtr, "level1" ) ) {
            genCases_setLevel( 1 );
        } else if ( ! strcmp( argPtr, "level2" ) ) {
            genCases_setLevel( 2 );
        } else if ( ! strcmp( argPtr, "errors" ) ) {
            if ( argc < 2 ) goto optionError;
            i = strtol( argv[1], (char **) &argPtr, 10 );
            if ( *argPtr ) goto optionError;
            verCases_maxErrorCount = i;
            --argc;
            ++argv;
        } else if ( ! strcmp( argPtr, "errorstop" ) ) {
            verCases_errorStop = true;
        } else if ( ! strcmp( argPtr, "forever" ) ) {
            genCases_setLevel( 2 );
            testLoops_forever = true;
        } else if (
            ! strcmp( argPtr, "checkNaNs" ) || ! strcmp( argPtr, "checknans" )
        ) {
            verCases_checkNaNs = true;
#ifdef EXTFLOAT80
        } else if ( ! strcmp( argPtr, "precision32" ) ) {
            roundingPrecision = 32;
        } else if ( ! strcmp( argPtr, "precision64" ) ) {
            roundingPrecision = 64;
        } else if ( ! strcmp( argPtr, "precision80" ) ) {
            roundingPrecision = 80;
#endif
        } else if (
               ! strcmp( argPtr, "rnear_even" )
            || ! strcmp( argPtr, "rneareven" )
            || ! strcmp( argPtr, "rnearest_even" )
        ) {
            roundingCode = ROUND_NEAR_EVEN;
        } else if (
            ! strcmp( argPtr, "rminmag" ) || ! strcmp( argPtr, "rminMag" )
        ) {
            roundingCode = ROUND_MINMAG;
        } else if ( ! strcmp( argPtr, "rmin" ) ) {
            roundingCode = ROUND_MIN;
        } else if ( ! strcmp( argPtr, "rmax" ) ) {
            roundingCode = ROUND_MAX;
        } else if (
               ! strcmp( argPtr, "rnear_maxmag" )
            || ! strcmp( argPtr, "rnear_maxMag" )
            || ! strcmp( argPtr, "rnearmaxmag" )
            || ! strcmp( argPtr, "rnearest_maxmag" )
            || ! strcmp( argPtr, "rnearest_maxMag" )
        ) {
#ifdef SUBJFLOAT_ROUND_NEAR_MAXMAG
            roundingCode = ROUND_NEAR_MAXMAG;
#else
            fail(
               "Rounding mode near_maxMag is not supported or cannot be tested"
            );
#endif
        } else if ( ! strcmp( argPtr, "tininessbefore" ) ) {
            softfloat_detectTininess = softfloat_tininess_beforeRounding;
        } else if ( ! strcmp( argPtr, "tininessafter" ) ) {
            softfloat_detectTininess = softfloat_tininess_afterRounding;
        } else if ( ! strcmp( argPtr, "all1" ) ) {
            haveFunctionArg = true;
            standardFunctionInfoPtr = 0;
            numOperands = 1;
        } else if ( ! strcmp( argPtr, "all2" ) ) {
            haveFunctionArg = true;
            standardFunctionInfoPtr = 0;
            numOperands = 2;
        } else {
            standardFunctionInfoPtr = standardFunctionInfos;
            for (;;) {
                functionNamePtr = standardFunctionInfoPtr->namePtr;
                if ( ! functionNamePtr ) {
                    fail( "Invalid argument `%s'", *argv );
                }
                if ( ! strcmp( argPtr, functionNamePtr ) ) break;
                ++standardFunctionInfoPtr;
            }
            subjFunctionPtr =
                subjfloat_functions
                    [standardFunctionInfoPtr - standardFunctionInfos];
            if ( ! subjFunctionPtr ) {
                fail(
                    "Function `%s' is not supported or cannot be tested",
                    argPtr
                );
            }
            haveFunctionArg = true;
        }
    }
    if ( ! haveFunctionArg ) fail( "Function argument required" );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    signal( SIGINT, catchSIGINT );
    signal( SIGTERM, catchSIGINT );
    if ( standardFunctionInfoPtr ) {
        if ( testLoops_forever ) {
            if ( ! roundingPrecision ) roundingPrecision = 80;
            if ( ! roundingCode ) roundingCode = ROUND_NEAR_EVEN;
        }
        testFunction(
            standardFunctionInfoPtr, roundingPrecision, roundingCode );
    } else {
        if ( testLoops_forever ) {
            fail( "Can test only one function with `-forever' option" );
        }
        if ( numOperands == 1 ) {
            standardFunctionInfoPtr = standardFunctionInfos;
            subjFunctionPtrPtr = subjfloat_functions;
            while ( standardFunctionInfoPtr->namePtr ) {
                subjFunctionPtr = *subjFunctionPtrPtr;
                if (
                    subjFunctionPtr
                        && ! (functionInfos
                                  [standardFunctionInfoPtr->functionCode]
                                  .attribs
                                  & FUNC_ARG_BINARY)
                ) {
                    testFunction(
                        standardFunctionInfoPtr,
                        roundingPrecision,
                        roundingCode
                    );
                }
                ++standardFunctionInfoPtr;
                ++subjFunctionPtrPtr;
            }
        } else {
            standardFunctionInfoPtr = standardFunctionInfos;
            subjFunctionPtrPtr = subjfloat_functions;
            while ( standardFunctionInfoPtr->namePtr ) {
                subjFunctionPtr = *subjFunctionPtrPtr;
                if (
                    subjFunctionPtr
                        && (functionInfos
                                [standardFunctionInfoPtr->functionCode]
                                .attribs
                                & FUNC_ARG_BINARY)
                ) {
                    testFunction(
                        standardFunctionInfoPtr,
                        roundingPrecision,
                        roundingCode
                    );
                }
                ++standardFunctionInfoPtr;
                ++subjFunctionPtrPtr;
            }
        }
    }
    verCases_exitWithStatus();
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 optionError:
    fail( "`%s' option requires numeric argument", *argv );

}
Пример #20
0
GTEST_TEST(ExpectedTest, ExpectedUniqueTestFunction) {
  auto uniquePointer = testFunction();
  EXPECT_TRUE(uniquePointer);
  EXPECT_EQ(**uniquePointer, "Test");
}
Пример #21
0
int main(int argc, char **argv)
{
	if(verbose)
		fprintf(stdout, "Benvingut a l'intèrpret de FastGameScript!\n\n");

	char c;
	
	while((c = getopt(argc, argv, "vgsdt")) != -1)
	{
		if(test)
			fprintf(stdout, "Found option %c\n", c);
		switch(c)
		{
			case 'v':
				verbose = 1;
				break;
			case 'g':
				bisonverbose = 1;
				break;
			case 's':
				stackverbose = 1;
				break;
			case 'd':
				debug = 1;
				break;
			case 't':
				test = 1;
				break;
			case '?':
				printf("Unknown option %c.", c);
				exit(3);
				break;
			default: 
				printf("This shouldn't happen?");
				exit(99);
				break;
		}
	}
	
	fgs_state *FGS;
	
	FGS = fgs_start_context();
	
	if(test)
		printf("--------------\n");

		
	/* Test */
	fgs_load_script(FGS, "test/prova_condicional_else.fgs");
	testFunction(FGS, "prova_condicional_else");
			
	/* Test */
	fgs_load_script(FGS, "test/prova_condicional_if.fgs");
	testFunction(FGS, "prova_condicional_if");
	
	/* Test */
	fgs_load_script(FGS, "test/prova_aritmetica_sum.fgs");
	testFunction(FGS, "prova_aritmetica_sum");
			
	
	/* Test */
	fgs_load_script(FGS, "test/prova_aritmetica_sum_parenth.fgs");
	testFunction(FGS, "prova_aritmetica_sum_parenth");
			
	/* Test */
	fgs_load_script(FGS, "test/prova_aritmetica_strings.fgs");
	testFunctionS(FGS, "prova_aritmetica_strings", "hola!");
			
	/* Test */
	fgs_load_script(FGS, "test/prova_fibonacci.fgs");
	push_valueI(FGS, 30);
	testFunctionI(FGS, "prova_fibonacci", 514229);
	push_valueF(FGS, 30.0f);
	testFunctionI(FGS, "prova_fibonacci", 514229);
			
	/* Test */
	push_valueI(FGS, 1);
	fgs_load_script(FGS, "test/prova_tipus_nou.fgs");
	testFunctionI(FGS, "prova_tipus_nou", 1);
			
	/* Test */
	fgs_load_script(FGS, "test/prova_aritmetica_parametres.fgs");
	push_valueI(FGS, 10);
	push_valueI(FGS, 10);
	testFunctionI(FGS, "suma", 20);

	/* Test: */
	fgs_load_script(FGS, "test/prova_aritmetica_return.fgs");
	push_valueI(FGS, 10);
	push_valueI(FGS, 10);
	testFunctionI(FGS, "suma", 20);

	/* Test: */
	fgs_load_script(FGS, "test/prova_funcions_repetides.fgs");
	push_valueI(FGS, 10);
	push_valueI(FGS, 10);
	testFunctionI(FGS, "resta", 0);
			
	/* Test */
	fgs_load_script(FGS, "test/prova_aritmetica_mul.fgs");
	testFunction(FGS, "prova_aritmetica_mul");
			
	/* test: */
	/*fgs_load_script(FGS, "test/prova_aritmetica_areatriangle.fgs");
	push_valueI(FGS, 10);
	push_valueI(FGS, 10);
	testFunctionI(FGS, "prova_aritmetica_areatriangle", 50);*/

	fgs_load_script(FGS, "test/prova_lexic_c.fgs");
	push_valueI(FGS, 1);
	testFunctionI(FGS, "prova_codi_c", 1);

	/* 
	/* Test: *
	fgs_load_script(FGS, "test/.fgs");
	testFunction(FGS, ""); */
	
	destroy_context(FGS);
	return 0;
}
Пример #22
0
int
main( int argc, char **argv )
{
    char *argPtr;
    flag functionArgument;
    uint8 functionCode;
    int8 operands, roundingPrecision, roundingMode;

    fail_programName = "testfloat";
    if ( argc <= 1 ) goto writeHelpMessage;
    testCases_setLevel( 1 );
    trueName = "soft";
    testName = "syst";
    errorStop = FALSE;
    forever = FALSE;
    maxErrorCount = 20;
    trueFlagsPtr = &float_exception_flags;
    testFlagsFunctionPtr = syst_float_flags_clear;
    tininessModeName = 0;
    functionArgument = FALSE;
    functionCode = 0;
    operands = 0;
    roundingPrecision = 0;
    roundingMode = 0;
    --argc;
    ++argv;
    while ( argc && ( argPtr = argv[ 0 ] ) ) {
        if ( argPtr[ 0 ] == '-' ) ++argPtr;
        if ( strcmp( argPtr, "help" ) == 0 ) {
 writeHelpMessage:
            fputs(
"testfloat [<option>...] <function>\n"
"  <option>:  (* is default)\n"
"    -help            --Write this message and exit.\n"
"    -list            --List all testable functions and exit.\n"
"    -level <num>     --Testing level <num> (1 or 2).\n"
" *  -level 1\n"
"    -errors <num>    --Stop each function test after <num> errors.\n"
" *  -errors 20\n"
"    -errorstop       --Exit after first function with any error.\n"
"    -forever         --Test one function repeatedly (implies `-level 2').\n"
"    -checkNaNs       --Check for bitwise correctness of NaN results.\n"
#ifdef FLOATX80
"    -precision32     --Only test rounding precision equivalent to float32.\n"
"    -precision64     --Only test rounding precision equivalent to float64.\n"
"    -precision80     --Only test maximum rounding precision.\n"
#endif
"    -nearesteven     --Only test rounding to nearest/even.\n"
"    -tozero          --Only test rounding to zero.\n"
"    -down            --Only test rounding down.\n"
"    -up              --Only test rounding up.\n"
"    -tininessbefore  --Underflow tininess detected before rounding.\n"
"    -tininessafter   --Underflow tininess detected after rounding.\n"
"  <function>:\n"
"    int32_to_<float>                 <float>_add   <float>_eq\n"
"    <float>_to_int32                 <float>_sub   <float>_le\n"
"    <float>_to_int32_round_to_zero   <float>_mul   <float>_lt\n"
#ifdef BITS64
"    int64_to_<float>                 <float>_div   <float>_eq_signaling\n"
"    <float>_to_int64                 <float>_rem   <float>_le_quiet\n"
"    <float>_to_int64_round_to_zero                 <float>_lt_quiet\n"
"    <float>_to_<float>\n"
"    <float>_round_to_int\n"
"    <float>_sqrt\n"
#else
"    <float>_to_<float>               <float>_div   <float>_eq_signaling\n"
"    <float>_round_to_int             <float>_rem   <float>_le_quiet\n"
"    <float>_sqrt                                   <float>_lt_quiet\n"
#endif
"    -all1            --All 1-operand functions.\n"
"    -all2            --All 2-operand functions.\n"
"    -all             --All functions.\n"
"  <float>:\n"
"    float32          --Single precision.\n"
"    float64          --Double precision.\n"
#ifdef FLOATX80
"    floatx80         --Extended double precision.\n"
#endif
#ifdef FLOAT128
"    float128         --Quadruple precision.\n"
#endif
                ,
                stdout
            );
            return EXIT_SUCCESS;
        }
        else if ( strcmp( argPtr, "list" ) == 0 ) {
            for ( functionCode = 1;
                  functionCode < NUM_FUNCTIONS;
                  ++functionCode
                ) {
                if ( functionExists[ functionCode ] ) {
                    puts( functions[ functionCode ].name );
                }
            }
            return EXIT_SUCCESS;
        }
        else if ( strcmp( argPtr, "level" ) == 0 ) {
            if ( argc < 2 ) goto optionError;
            testCases_setLevel( atoi( argv[ 1 ] ) );
            --argc;
            ++argv;
        }
        else if ( strcmp( argPtr, "level1" ) == 0 ) {
            testCases_setLevel( 1 );
        }
        else if ( strcmp( argPtr, "level2" ) == 0 ) {
            testCases_setLevel( 2 );
        }
        else if ( strcmp( argPtr, "errors" ) == 0 ) {
            if ( argc < 2 ) {
     optionError:
                fail( "`%s' option requires numeric argument", argv[ 0 ] );
            }
            maxErrorCount = atoi( argv[ 1 ] );
            --argc;
            ++argv;
        }
        else if ( strcmp( argPtr, "errorstop" ) == 0 ) {
            errorStop = TRUE;
        }
        else if ( strcmp( argPtr, "forever" ) == 0 ) {
            testCases_setLevel( 2 );
            forever = TRUE;
        }
        else if (    ( strcmp( argPtr, "checkNaNs" ) == 0 )
                  || ( strcmp( argPtr, "checknans" ) == 0 ) ) {
            checkNaNs = TRUE;
        }
#ifdef FLOATX80
        else if ( strcmp( argPtr, "precision32" ) == 0 ) {
            roundingPrecision = 32;
        }
        else if ( strcmp( argPtr, "precision64" ) == 0 ) {
            roundingPrecision = 64;
        }
        else if ( strcmp( argPtr, "precision80" ) == 0 ) {
            roundingPrecision = 80;
        }
#endif
        else if (    ( strcmp( argPtr, "nearesteven" ) == 0 )
                  || ( strcmp( argPtr, "nearest_even" ) == 0 ) ) {
            roundingMode = ROUND_NEAREST_EVEN;
        }
        else if (    ( strcmp( argPtr, "tozero" ) == 0 )
                  || ( strcmp( argPtr, "to_zero" ) == 0 ) ) {
            roundingMode = ROUND_TO_ZERO;
        }
        else if ( strcmp( argPtr, "down" ) == 0 ) {
            roundingMode = ROUND_DOWN;
        }
        else if ( strcmp( argPtr, "up" ) == 0 ) {
            roundingMode = ROUND_UP;
        }
        else if ( strcmp( argPtr, "tininessbefore" ) == 0 ) {
            float_detect_tininess = float_tininess_before_rounding;
        }
        else if ( strcmp( argPtr, "tininessafter" ) == 0 ) {
            float_detect_tininess = float_tininess_after_rounding;
        }
        else if ( strcmp( argPtr, "all1" ) == 0 ) {
            functionArgument = TRUE;
            functionCode = 0;
            operands = 1;
        }
        else if ( strcmp( argPtr, "all2" ) == 0 ) {
            functionArgument = TRUE;
            functionCode = 0;
            operands = 2;
        }
        else if ( strcmp( argPtr, "all" ) == 0 ) {
            functionArgument = TRUE;
            functionCode = 0;
            operands = 0;
        }
        else {
            for ( functionCode = 1;
                  functionCode < NUM_FUNCTIONS;
                  ++functionCode
                ) {
                if ( strcmp( argPtr, functions[ functionCode ].name ) == 0 ) {
                    break;
                }
            }
            if ( functionCode == NUM_FUNCTIONS ) {
                fail( "Invalid option or function `%s'", argv[ 0 ] );
            }
            if ( ! functionExists[ functionCode ] ) {
                fail(
                    "Function `%s' is not supported or cannot be tested",
                    argPtr
                );
            }
            functionArgument = TRUE;
        }
        --argc;
        ++argv;
    }
    if ( ! functionArgument ) fail( "Function argument required" );
    (void) signal( SIGINT, catchSIGINT );
    (void) signal( SIGTERM, catchSIGINT );
    if ( functionCode ) {
        if ( forever ) {
            if ( ! roundingPrecision ) roundingPrecision = 80;
            if ( ! roundingMode ) roundingMode = ROUND_NEAREST_EVEN;
        }
        testFunction( functionCode, roundingPrecision, roundingMode );
    }
    else {
        if ( forever ) {
            fail( "Can only test one function with `-forever' option" );
        }
        if ( operands == 1 ) {
            for ( functionCode = 1;
                  functionCode < NUM_FUNCTIONS;
                  ++functionCode
                ) {
                if (    functionExists[ functionCode ]
                     && ( functions[ functionCode ].numInputs == 1 ) ) {
                    testFunction(
                        functionCode, roundingPrecision, roundingMode );
                }
            }
        }
        else if ( operands == 2 ) {
            for ( functionCode = 1;
                  functionCode < NUM_FUNCTIONS;
                  ++functionCode
                ) {
                if (    functionExists[ functionCode ]
                     && ( functions[ functionCode ].numInputs == 2 ) ) {
                    testFunction(
                        functionCode, roundingPrecision, roundingMode );
                }
            }
        }
        else {
            for ( functionCode = 1;
                  functionCode < NUM_FUNCTIONS;
                  ++functionCode
                ) {
                if ( functionExists[ functionCode ] ) {
                    testFunction(
                        functionCode, roundingPrecision, roundingMode );
                }
            }
        }
    }
    exitWithStatus();

}
Пример #23
0
int main( int argc, char *argv[] )
{
    bool haveFunctionArg;
    int functionCode, numOperands;
    uint_fast8_t roundingPrecision;
    int roundingCode, tininessCode, exactCode;
    const char *argPtr;
    unsigned long ui;
    long i;

    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    fail_programName = "testsoftfloat";
    if ( argc <= 1 ) goto writeHelpMessage;
    genCases_setLevel( 1 );
    verCases_maxErrorCount = 20;
    testLoops_trueFlagsPtr = &slowfloat_exceptionFlags;
    testLoops_subjFlagsFunction = softfloat_clearExceptionFlags;
    haveFunctionArg = false;
    functionCode = 0;
    numOperands = 0;
    roundingPrecision = 0;
    roundingCode = 0;
    tininessCode = 0;
    exactCode = 0;
    for (;;) {
        --argc;
        if ( ! argc ) break;
        argPtr = *++argv;
        if ( ! argPtr ) break;
        if ( argPtr[0] == '-' ) ++argPtr;
        if (
            ! strcmp( argPtr, "help" ) || ! strcmp( argPtr, "-help" )
                || ! strcmp( argPtr, "h" )
        ) {
 writeHelpMessage:
            fputs(
"testsoftfloat [<option>...] <function>\n"
"  <option>:  (* is default)\n"
"    -help            --Write this message and exit.\n"
"    -seed <num>      --Set pseudo-random number generator seed to <num>.\n"
" *  -seed 1\n"
"    -level <num>     --Testing level <num> (1 or 2).\n"
" *  -level 1\n"
"    -errors <num>    --Stop each function test after <num> errors.\n"
" *  -errors 20\n"
"    -errorstop       --Exit after first function with any error.\n"
"    -forever         --Test one function repeatedly (implies `-level 2').\n"
#ifdef EXTFLOAT80
"    -precision32     --For extF80, test only 32-bit rounding precision.\n"
"    -precision64     --For extF80, test only 64-bit rounding precision.\n"
"    -precision80     --For extF80, test only 80-bit rounding precision.\n"
#endif
"    -rnear_even      --Test only rounding to nearest/even.\n"
"    -rminMag         --Test only rounding to minimum magnitude (toward zero).\n"
"    -rmin            --Test only rounding to minimum (down).\n"
"    -rmax            --Test only rounding to maximum (up).\n"
"    -rnear_maxMag    --Test only rounding to nearest/maximum magnitude\n"
"                         (nearest/away).\n"
"    -tininessbefore  --Test only underflow tininess detected before rounding.\n"
"    -tininessafter   --Test only underflow tininess detected after rounding.\n"
"    -notexact        --Test only non-exact rounding to integer (no inexact\n"
"                         exceptions).\n"
"    -exact           --Test only exact rounding to integer (raising inexact\n"
"                         exceptions).\n"
"  <function>:\n"
"    <int>_to_<float>            <float>_add      <float>_eq\n"
"    <float>_to_<int>            <float>_sub      <float>_le\n"
"    <float>_to_<int>_r_minMag   <float>_mul      <float>_lt\n"
"    <float>_to_<float>          <float>_mulAdd   <float>_eq_signaling\n"
"    <float>_roundToInt          <float>_div      <float>_le_quiet\n"
"                                <float>_rem      <float>_lt_quiet\n"
"                                <float>_sqrt\n"
"    -all1            --All unary functions.\n"
"    -all2            --All binary functions.\n"
"  <int>:\n"
"    ui32             --Unsigned 32-bit integer.\n"
"    ui64             --Unsigned 64-bit integer.\n"
"    i32              --Signed 32-bit integer.\n"
"    i64              --Signed 64-bit integer.\n"
"  <float>:\n"
#ifdef FLOAT16
"    f16              --Binary 16-bit floating-point (half-precision).\n"
#endif
"    f32              --Binary 32-bit floating-point (single-precision).\n"
"    f64              --Binary 64-bit floating-point (double-precision).\n"
#ifdef EXTFLOAT80
"    extF80           --Binary 80-bit extended floating-point.\n"
#endif
#ifdef FLOAT128
"    f128             --Binary 128-bit floating-point (quadruple-precision).\n"
#endif
                ,
                stdout
            );
            return EXIT_SUCCESS;
        } else if ( ! strcmp( argPtr, "seed" ) ) {
            if ( argc < 2 ) goto optionError;
            ui = strtoul( argv[1], (char **) &argPtr, 10 );
            if ( *argPtr ) goto optionError;
            srand( ui );
            --argc;
            ++argv;
        } else if ( ! strcmp( argPtr, "level" ) ) {
            if ( argc < 2 ) goto optionError;
            i = strtol( argv[1], (char **) &argPtr, 10 );
            if ( *argPtr ) goto optionError;
            genCases_setLevel( i );
            --argc;
            ++argv;
        } else if ( ! strcmp( argPtr, "level1" ) ) {
            genCases_setLevel( 1 );
        } else if ( ! strcmp( argPtr, "level2" ) ) {
            genCases_setLevel( 2 );
        } else if ( ! strcmp( argPtr, "errors" ) ) {
            if ( argc < 2 ) goto optionError;
            i = strtol( argv[1], (char **) &argPtr, 10 );
            if ( *argPtr ) goto optionError;
            verCases_maxErrorCount = i;
            --argc;
            ++argv;
        } else if ( ! strcmp( argPtr, "errorstop" ) ) {
            verCases_errorStop = true;
        } else if ( ! strcmp( argPtr, "forever" ) ) {
            genCases_setLevel( 2 );
            testLoops_forever = true;
#ifdef EXTFLOAT80
        } else if ( ! strcmp( argPtr, "precision32" ) ) {
            roundingPrecision = 32;
        } else if ( ! strcmp( argPtr, "precision64" ) ) {
            roundingPrecision = 64;
        } else if ( ! strcmp( argPtr, "precision80" ) ) {
            roundingPrecision = 80;
#endif
        } else if (
               ! strcmp( argPtr, "rnear_even" )
            || ! strcmp( argPtr, "rneareven" )
            || ! strcmp( argPtr, "rnearest_even" )
        ) {
            roundingCode = ROUND_NEAR_EVEN;
        } else if (
            ! strcmp( argPtr, "rminmag" ) || ! strcmp( argPtr, "rminMag" )
        ) {
            roundingCode = ROUND_MINMAG;
        } else if ( ! strcmp( argPtr, "rmin" ) ) {
            roundingCode = ROUND_MIN;
        } else if ( ! strcmp( argPtr, "rmax" ) ) {
            roundingCode = ROUND_MAX;
        } else if (
               ! strcmp( argPtr, "rnear_maxmag" )
            || ! strcmp( argPtr, "rnear_maxMag" )
            || ! strcmp( argPtr, "rnearmaxmag" )
            || ! strcmp( argPtr, "rnearest_maxmag" )
            || ! strcmp( argPtr, "rnearest_maxMag" )
        ) {
            roundingCode = ROUND_NEAR_MAXMAG;
        } else if ( ! strcmp( argPtr, "tininessbefore" ) ) {
            tininessCode = TININESS_BEFORE_ROUNDING;
        } else if ( ! strcmp( argPtr, "tininessafter" ) ) {
            tininessCode = TININESS_AFTER_ROUNDING;
        } else if ( ! strcmp( argPtr, "notexact" ) ) {
            exactCode = EXACT_FALSE;
        } else if ( ! strcmp( argPtr, "exact" ) ) {
            exactCode = EXACT_TRUE;
        } else if ( ! strcmp( argPtr, "all1" ) ) {
            haveFunctionArg = true;
            functionCode = 0;
            numOperands = 1;
        } else if ( ! strcmp( argPtr, "all2" ) ) {
            haveFunctionArg = true;
            functionCode = 0;
            numOperands = 2;
        } else {
            functionCode = 1;
            while ( strcmp( argPtr, functionInfos[functionCode].namePtr ) ) {
                ++functionCode;
                if ( functionCode == NUM_FUNCTIONS ) {
                    fail( "Invalid argument `%s'", *argv );
                }
            }
            haveFunctionArg = true;
        }
    }
    if ( ! haveFunctionArg ) fail( "Function argument required" );
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
    signal( SIGINT, catchSIGINT );
    signal( SIGTERM, catchSIGINT );
    if ( functionCode ) {
        if ( testLoops_forever ) {
            if ( ! roundingPrecision ) roundingPrecision = 80;
            if ( ! roundingCode ) roundingCode = ROUND_NEAR_EVEN;
        }
        testFunction(
            functionCode,
            roundingPrecision,
            roundingCode,
            tininessCode,
            exactCode
        );
    } else {
        if ( testLoops_forever ) {
             fail( "Can test only one function with `-forever' option" );
        }
        if ( numOperands == 1 ) {
            for (
                functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode
            ) {
                if ( functionInfos[functionCode].attribs & FUNC_ARG_UNARY ) {
                    testFunction(
                        functionCode,
                        roundingPrecision,
                        roundingCode,
                        tininessCode,
                        exactCode
                    );
                }
            }
        } else {
            for (
                functionCode = 1; functionCode < NUM_FUNCTIONS; ++functionCode
            ) {
                if (
                    functionInfos[functionCode].attribs & FUNC_ARG_BINARY
                ) {
                    testFunction(
                        functionCode,
                        roundingPrecision,
                        roundingCode,
                        tininessCode,
                        exactCode
                    );
                }
            }
        }
    }
    verCases_exitWithStatus();
    /*------------------------------------------------------------------------
    *------------------------------------------------------------------------*/
 optionError:
    fail( "`%s' option requires numeric argument", *argv );

}
Пример #24
0
int main(){
  double a = testFunction(0.0);
  return (int) a;
}
Пример #25
0
int main() {
	printf("This is a test\n");
	testFunction(29);

	return 0;
}