Files
yallie 9fa3874800 Added the contents of the archive.
Moved the original file to the archive subfolder.
2017-11-20 16:11:42 +03:00

213 lines
7.3 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 Co2482Reverse
{
public static String strName = "ArrayList.Reverse";
public static String strTest = "Co2482Reverse";
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( 0, arrList.Count );
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;
Console.Error.WriteLine( "[] Attempt bogus Reverse using negative index" );
try
{
arrList.Reverse( -100, arrList.Count );
Console.WriteLine( strTest+ "E_303: Expected ArgumentException" );
++iCountErrors;
break;
}
catch (ArgumentException ex)
{
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10003: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
++iCountTestcases;
Console.Error.WriteLine( "[] Attempt Reverse using out of range index" );
try
{
arrList.Reverse( 1000, arrList.Count );
Console.WriteLine( strTest+ "E_404: Expected ArgumentException" );
++iCountErrors;
break;
}
catch (ArgumentException ex)
{
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10004: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
++iCountTestcases;
Console.Error.WriteLine( "[] Attempt Reverse using negative count" );
try
{
arrList.Reverse( 0, -arrList.Count );
Console.WriteLine( strTest+ "E_505: Expected ArgumentException" );
++iCountErrors;
break;
}
catch (ArgumentException ex)
{
}
catch (Exception ex)
{
Console.WriteLine( strTest+ "E_10005: Unexpected Exception: " + ex.ToString() );
++iCountErrors;
break;
}
++iCountTestcases;
Console.Error.WriteLine( "[] Attempt Reverse using zero count" );
try
{
arrList.Reverse( 0, 0 );
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_10005: 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
{
System.String strFailMsg = null;
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;
Co2482Reverse oCbTest = new Co2482Reverse();
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;
}
}