mirror of
https://github.com/SSCLI/sscli_20021101
synced 2026-06-08 12:28:57 +00:00
9fa3874800
Moved the original file to the archive subfolder.
157 lines
4.9 KiB
C#
157 lines
4.9 KiB
C#
// ==++==
|
|
//
|
|
//
|
|
// Copyright (c) 2002 Microsoft Corporation. All rights reserved.
|
|
//
|
|
// The use and distribution terms for this software are contained in the file
|
|
// named license.txt, which can be found in the root of this distribution.
|
|
// By using this software in any fashion, you are agreeing to be bound by the
|
|
// terms of this license.
|
|
//
|
|
// You must not remove this notice, or any other, from this software.
|
|
//
|
|
//
|
|
// ==--==
|
|
using System.IO;
|
|
using System;
|
|
using System.Collections;
|
|
public class Co3932Reverse
|
|
{
|
|
public static String strName = "ArrayList.Reverse";
|
|
public static String strTest = "Co3932Reverse";
|
|
public static String strPath = "";
|
|
public virtual bool runTest()
|
|
{
|
|
int iCountErrors = 0;
|
|
int iCountTestcases = 0;
|
|
Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
|
|
ArrayList arrList = null;
|
|
String [] strHeroes =
|
|
{
|
|
"Aquaman",
|
|
"Atom",
|
|
"Batman",
|
|
"Black Canary",
|
|
"Captain America",
|
|
"Captain Atom",
|
|
"Catwoman",
|
|
"Cyborg",
|
|
"Flash",
|
|
"Green Arrow",
|
|
"Green Lantern",
|
|
"Hawkman",
|
|
"Huntress",
|
|
"Ironman",
|
|
"Nightwing",
|
|
"Robin",
|
|
"SpiderMan",
|
|
"Steel",
|
|
"Superman",
|
|
"Thor",
|
|
"Wildcat",
|
|
"Wonder Woman",
|
|
};
|
|
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 ArrayList1" );
|
|
++iCountErrors;
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
|
|
++iCountErrors;
|
|
break;
|
|
}
|
|
++iCountTestcases;
|
|
Console.Error.WriteLine( "[] Reverse entire array list" );
|
|
try
|
|
{
|
|
arrList.Reverse( );
|
|
for ( int ii = 0; ii < arrList.Count; ++ii )
|
|
{
|
|
if ( strHeroes[ii].CompareTo( (String)arrList[arrList.Count-ii-1] ) != 0 )
|
|
{
|
|
String strInfo = strTest + " error: ";
|
|
strInfo = strInfo + "Expected hero <"+ strHeroes[ii] + "> ";
|
|
strInfo = strInfo + "Returned hero <"+ (String)arrList[ii+arrList.Count-1] + "> ";
|
|
Console.WriteLine( strTest+ "E_202: " + strInfo );
|
|
++iCountErrors;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine( strTest+ "E_10002: Unexpected Exception: " + ex.ToString() );
|
|
++iCountErrors;
|
|
break;
|
|
}
|
|
++iCountTestcases;
|
|
arrList = new ArrayList();
|
|
try
|
|
{
|
|
arrList.Reverse();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
++iCountErrors;
|
|
Console.WriteLine("Err_7842f! Unexpected exception thrown, " + ex);
|
|
}
|
|
arrList = new ArrayList();
|
|
for(int i=0; i<1; i++)
|
|
arrList.Add(i);
|
|
try
|
|
{
|
|
arrList.Reverse();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
++iCountErrors;
|
|
Console.WriteLine("Err_7842f! Unexpected exception thrown, " + ex);
|
|
}
|
|
}
|
|
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 )
|
|
{
|
|
bool bResult = false;
|
|
Co3932Reverse oCbTest = new Co3932Reverse();
|
|
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;
|
|
}
|
|
}
|