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 )