Пример #1
0
int tee_para( void )
    {
    int r;

    switch ( tyybinr )
	    {
	    case 0:                     /* muutumatu sõna */
	        return(1);

	    case 1:			    /* vallatu S 1 */
	        r = par1();
	        break;

	    case 2:                               /* õpik õpiku S 2 */
	        r = par2();
	        break;

	    case 3:              /* sama, mis case 2:   vaher vahtra S 3 */
	        r = par3();
	        break;

	    case 4:                              /* ase aseme S 4 */
	        r = par4();
	        break;

	    case 5:           /* sama, mis case 4:    liige liikme S 5 */
	        r = par5();
	        break;

	    case 6:                                      /* mõte mõtte S 6 */
	        r = par6();
	        break;

	    case 7:                 /* sama, mis case 6:     hammas hamba S 7 */
	        r = par7();
	        break;

	    case 8:    /* erineb case 6-st mitmuse tunnuse poolest  tütar tütre S 7 */
	        r = par8();
	        break;

	    case 9:             /* sama, mis case 6:  katus katuse S 9 */
	        r = par9();
	        break;

	    case 10:                          /* soolane soolase soolas[t A 10 */
	        r = par10();
	        break;

	    case 11:                          /* harjutus harjutuse S 11 i */
	        r = par11();
	        break;

	    case 12:                          /*oluline olulise olulis[t A 12 i */
	        r = par12();
	        break;

	    case 13:                          /* suur suure suur[te A 13 i */
	        r = par13();
	        break;

	    case 14:                        /* uus uue uu[t uu[te (uusi) A 14 i */
	        r = par14();
	        break;

	    case 15:                          /* käsi käe kä[tt kä[te S 15 */
	        r = par15();
	        break;

	    case 16:                          /* kõne kõnne S 16 */
	        r = par16();
	        break;

	    case 17:                          /* saba sappa S 17 u */
	        r = par17();
	        break;

	    case 18:                          /* sõda sõja sõtta S 18 u */
	        r = par18();
	        break;

	    case 19:                          /* seminar seminari S 19 e */
	        r = par19();
	        break;

	    case 20:                          /* nimi nime (nimme) S 20 */
	        r = par20();
	        break;

	    case 21:                          /* jõgi jõge jõe jõkke S 20 */
	        r = par21();
	        break;

	    case 22:                          /* sepp seppa sepa S 22 i */
	        r = par22();
	        break;

	    case 23:                          /* hein h'eina heina heinte S 23 u */
	        r = par23();
	        break;

	    case 24:                          /* padi patja padja S 24 u */
	        r = par24();
	        break;

	    case 25:                    /* õnnelik õnnelikku õnneliku S 25 e */
	        r = par25();
	        break;

	    case 26:                    /* idee {ee->e[i} S 26 */
	        r = par26();
	        break;

	    default:
	        return(0);          /* "võimatu" nr */
	    }
    if ( !r )
	    return(0);
    if ( plural )
	    {
	    r = eemalda_ainsus();
	    if ( !r )
	        return(0);
	    }
    if ( singular )
	    {
	    r = eemalda_mitmus();
	    if ( !r )
	        return(0);
	    r = eemalda_mitmus();
	    }
    return(1);
    }
Пример #2
0
/// @file unit_tests/genieRoom.cpp
/// @brief unit test function for function that implements genieRoom
///
/// @param harnessOutput is a reference to an opened file for harness results
/// @param harnessError is a reference to an opened file for harness errors
/// @param input is the location of the input file that will be utilized
///         this is an optional parameter and if not specified will be NULL
///
void testFunction(std::ofstream &harnessOutput, std::ofstream &harnessError, 
                  char *input = NULL)
{
    bool proper = false;

    // update return value type to be of expected type
    // std::string ret_val;
    std::ofstream inputFile;
    
    // Answers that are expected, only one char expected at a time
    int ansA[] = {3, 6, 0};
    vector <int> ans(ansA, ansA + sizeof(ansA) / sizeof(ansA[0]));
    
    int ansB[] = {2, 5, 0};
    vector <int> ans2(ansB, ansB + sizeof(ansB) / sizeof(ansB[0]));

    int ansC[] = {7, 2, 0};
    vector <int> ans3(ansC, ansC + sizeof(ansC) / sizeof(ansC[0]));

    // Parameters to provide function -- one vector per parameter
    int parB[] = {723, 256, 0};
    vector <int> par(parB, parB + sizeof(parB) / sizeof(parB[0]));

    int parA[] = {10, 10, 10};
    vector <int> par2(parA, parA + sizeof(parA) / sizeof(parA[0]));
    vector <int> par3(parA, parA + sizeof(parA) / sizeof(parA[0]));
    vector <int> par4(parA, parA + sizeof(parA) / sizeof(parA[0]));

    // Create input file if warranted 
    // Single test case's input per line, cin.ignore '\n' utilized after test
    vector <std::string> input_contents;
    if (input != NULL)
    {
        // input file contents can always go out as strings
        input_contents.push_back("e");    

        // extra inputs should change depending on what sort of valid inputs
        // are to be expected by the program
        std::string extra = "a b c d e f g h i j k l m n o p q ";

        // clear the file before writing, write out input and extra per line
        inputFile.open(input, ios::out | ios::trunc);
        for (int i = 0; i < input_contents.size(); i++)    
        {
            inputFile << input_contents.at(i) << " " << extra << std::endl 
                << std::endl;
        }
        inputFile.close(); 
    }       

    // go through every test in the unit test (each test has 1 answer)
    for (int i=0; i < ans.size(); i++)
    {
        // section title for output, script should replace the generic name
        std::string call = "Calling STUDENT_FUNC_NAME(";
        call = call + convertInt(par.at(i)) + ", var1, var2, var3) ";
        call = call + "// initial values var1, var2, var3: ";
        call = call + convertInt(par2.at(i)) + ", " + convertInt(par3.at(i));
        call = call + ", " + convertInt(par4.at(i));

        try
        {
            // output the section title to standard output so it precedes
            // any function output within standard out for this individual test
            std::cout << call << std::endl;

            // call to generic function, script should replace the name
            STUDENT_FUNC_NAME(par.at(i), par2.at(i), par3.at(i), par4.at(i));

            // determine if the return value is what is expected
            proper = ans.at(i) == par2.at(i) && ans2.at(i) == par3.at(i);
            proper = proper && (ans3.at(i) == par4.at(i));
            if (!proper)
            {
                // tab separation utilized to break up title and items that 
                // should exist in a list below the title

                // output section title to harness output
                harnessOutput << call;
                harnessOutput << "\t";

                // output what was expected
                harnessOutput << "Expected Result: ";
                harnessOutput << "var1 = " << ans.at(i);
                harnessOutput << ", var2 = " << ans2.at(i);
                harnessOutput << ", var3 = " << ans3.at(i);
                harnessOutput << "\t";

                // output what was returned by the function call
                harnessOutput << "Received: ";
                harnessOutput << "var1 = " << par2.at(i);
                harnessOutput << ", var2 = " << par3.at(i);
                harnessOutput << ", var3 = " << par4.at(i);
                
                // output the input file contents for this test if warranted
                if (input != NULL)
                {
                    harnessOutput << "\t";
                    harnessOutput << "Input File Conents: ";
                    harnessOutput << input_contents.at(i);
                }
                harnessOutput << std::endl;
            }
        }
        catch(out_of_range& oor)
        {
            // Catch out of range errors, output section title and what threw
            // the exception separated by a tab, similar to harnessOutput
            harnessError << call;
            harnessError << "\t";
            harnessError << "Out of Range exception thrown by: ";
            harnessError << oor.what() << std::endl;
            
        }
        catch(...)
        {
            // Catch all other exceptions, output section title and a simple
            // statement that an exception was thrown
            harnessError << call;
            harnessError << "\t";
            harnessError << "exception thrown" << std::endl;
        }

        // The next test's input will be after the next newline
        if (input != NULL)
        {
            std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
        }
    }
}