Co3929LastIndexOf_O.runTest C# (CSharp) Method

runTest() public method

public runTest ( ) : bool
return bool
    public virtual bool runTest()
    {
        int iCountErrors = 0;
        int iCountTestcases = 0;
        Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
        ArrayList arrList = null;
        int ndx = -1;
        String [] strHeroes =
        {
            "Aquaman",
            "Atom",
            "Batman",
            "Black Canary",
            "Captain America",
            "Captain Atom",
            "Batman",
            "Catwoman",
            "Cyborg",
            "Flash",
            "Green Arrow",
            "Batman",
            "Green Lantern",
            "Hawkman",
            "Huntress",
            "Ironman",
            "Nightwing",
            "Batman",
            "Robin",
            "SpiderMan",
            "Steel",
            "Superman",
            "Thor",
            "Batman",
            "Wildcat",
            "Wonder Woman",
            "Batman",
        };
        do
        {
            ++iCountTestcases;
            Console.Error.WriteLine( "[]  Construct ArrayList" );
            try
            {
                arrList = new ArrayList( (ICollection) strHeroes );
                if ( arrList == null )
                {
                    Console.WriteLine( strTest+ "E_101: Failed to construct new ArrayList" );
                    ++iCountErrors;
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
                ++iCountErrors;
                break;
            }
            ++iCountTestcases;
            Console.Error.WriteLine( "[]  Obtain last index of \"Batman\" items" );
            try
            {
                if( ( ndx = arrList.LastIndexOf( "Batman") ) != -1 )
                {
                    if ( strHeroes[ndx].CompareTo( (String)arrList[ndx] ) != 0 )
                    {
                        String strInfo = strTest + " error: ";
                        strInfo = strInfo + "On LastIndexOf==" + ndx + " ";
                        strInfo = strInfo + "Expected hero <"+ strHeroes[ndx] + "> ";
                        strInfo = strInfo + "Returned hero <"+ (String)arrList[ndx] + "> ";
                        Console.WriteLine( strTest+ "E_202: " + strInfo );
                        ++iCountErrors;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
                ++iCountErrors;
                break;
            }
            ++iCountTestcases;
            Console.Error.WriteLine( "[]  Attempt to find null object" );
            try
            {
                ndx = arrList.LastIndexOf( null);
                if ( ndx != -1 )
                {
                    String strInfo = strTest + " error: ";
                    strInfo = strInfo + "Expected index <-1> ";
                    strInfo = strInfo + "Returned index <"+ ndx + "> ";
                    Console.WriteLine( strTest+ "E_303: " + strInfo );
                    ++iCountErrors;
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine( strTest+ "E_10003: Unexpected Exception: " + ex.ToString() );
                ++iCountErrors;
                break;
            }
        }
        while ( false );
        Console.Error.Write( strName );
        Console.Error.Write( ": " );
        if ( iCountErrors == 0 )
        {
            Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
            return true;
        }
        else
        {
            Console.WriteLine( strTest+ strPath );
            Console.WriteLine( strTest+ "FAiL" );
            Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
            return false;
        }
    }
    public static void Main( String[] args )

Usage Example

Esempio n. 1
0
    public static void Main(String[] args)
    {
        bool bResult = false;
        Co3929LastIndexOf_O oCbTest = new Co3929LastIndexOf_O();

        try
        {
            bResult = oCbTest.runTest();
        }
        catch (Exception ex)
        {
            bResult = false;
            Console.WriteLine(strTest + strPath);
            Console.WriteLine(strTest + "E_1000000");
            Console.WriteLine(strTest + "FAiL: Uncaught exception detected in Main()");
            Console.WriteLine(strTest + ex.ToString());
        }
        if (bResult == true)
        {
            Environment.ExitCode = 0;
        }
        else
        {
            Environment.ExitCode = 1;
        }
    }
All Usage Examples Of Co3929LastIndexOf_O::runTest
Co3929LastIndexOf_O