コード例 #1
0
		};	// s_aint64Examples

        public static void Exercise ( string pstrReportFileName )
        {
            const string HEXADECIMAL_8 = @"X8";
			const string BITMASK_FORMAT_STRING = "G";

			int intTestNbr = TestBit32ArrayToStringOverload ( );
			TestBitArrayRulers ( ref intTestNbr );
			TestBitMaskAndRuler ( ref intTestNbr );

            Console.WriteLine ( @"Begin BitArray32TestStand Exercises" );
            Console.WriteLine ( @"{1}    Test # {0} - Display public constants.{1}" , ++intTestNbr , Environment.NewLine );

			Console.WriteLine ( 
				"        Bit  1      = {0} (Individual bits: {1})" ,			// Format control string
				BitArray32.BIT_01.ToString ( HEXADECIMAL_8 ) ,					// Format Item 0 = Bit as hexadecimal integer
				BitArray32.FormatIntegerAsBitArray (							// Format Item 1 = Bit as array of bits
					BitArray32.BIT_01 ,											// Specify the same bit, raw.
					BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );					// This should be passing a value of 1.

			Console.WriteLine ( @"        Bit  2      = {0} (Individual bits: {1})" , BitArray32.BIT_02.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_02 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  3      = {0} (Individual bits: {1})" , BitArray32.BIT_03.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_03 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  4      = {0} (Individual bits: {1})" , BitArray32.BIT_04.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_04 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  5      = {0} (Individual bits: {1})" , BitArray32.BIT_05.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_05 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  6      = {0} (Individual bits: {1})" , BitArray32.BIT_06.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_06 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  7      = {0} (Individual bits: {1})" , BitArray32.BIT_07.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_07 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  8      = {0} (Individual bits: {1})" , BitArray32.BIT_08.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_08 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit  9      = {0} (Individual bits: {1})" , BitArray32.BIT_09.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_09 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit 10      = {0} (Individual bits: {1})" , BitArray32.BIT_10.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_10 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );

			Console.WriteLine ( @"        Bit 11      = {0} (Individual bits: {1})" , BitArray32.BIT_11.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_11 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit 12      = {0} (Individual bits: {1})" , BitArray32.BIT_12.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_12 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit 13      = {0} (Individual bits: {1})" , BitArray32.BIT_13.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_13 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit 14      = {0} (Individual bits: {1})" , BitArray32.BIT_14.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_14 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 15      = {0} (Individual bits: {1})" , BitArray32.BIT_15.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_15 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 16      = {0} (Individual bits: {1})" , BitArray32.BIT_16.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_16 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 17      = {0} (Individual bits: {1})" , BitArray32.BIT_17.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_17 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 18      = {0} (Individual bits: {1})" , BitArray32.BIT_18.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_18 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 19      = {0} (Individual bits: {1})" , BitArray32.BIT_19.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_19 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 20      = {0} (Individual bits: {1})" , BitArray32.BIT_20.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_20 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );

			Console.WriteLine ( @"        Bit 21      = {0} (Individual bits: {1})" , BitArray32.BIT_21.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_21 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        Bit 22      = {0} (Individual bits: {1})" , BitArray32.BIT_22.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_22 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 23      = {0} (Individual bits: {1})" , BitArray32.BIT_23.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_23 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 24      = {0} (Individual bits: {1})" , BitArray32.BIT_24.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_24 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 25      = {0} (Individual bits: {1})" , BitArray32.BIT_25.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_25 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 26      = {0} (Individual bits: {1})" , BitArray32.BIT_26.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_26 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 27      = {0} (Individual bits: {1})" , BitArray32.BIT_27.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_27 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 28      = {0} (Individual bits: {1})" , BitArray32.BIT_28.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_28 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 29      = {0} (Individual bits: {1})" , BitArray32.BIT_29.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_29 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 30      = {0} (Individual bits: {1})" , BitArray32.BIT_30.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_30 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );

            Console.WriteLine ( @"        Bit 31      = {0} (Individual bits: {1})" , BitArray32.BIT_31.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_31 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
            Console.WriteLine ( @"        Bit 32      = {0} (Individual bits: {1})" , BitArray32.BIT_32.ToString ( HEXADECIMAL_8 ) , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_32 , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );

			Console.WriteLine ( @"        BIT_NBR_MIN = {0} (Individual bits: {1})" , BitArray32.BIT_NBR_MIN , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_NBR_MIN , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );
			Console.WriteLine ( @"        BIT_NBR_MAX = {0} (Individual bits: {1})" , BitArray32.BIT_NBR_MAX , BitArray32.FormatIntegerAsBitArray ( BitArray32.BIT_NBR_MAX , BitArray32.MINIMUM_BIT_GROUP_IN_FORMAT ) );

			Console.WriteLine ( @"        OFF         = {0}" , BitArray32.OFF );
			Console.WriteLine ( @"        ON          = {0}" , BitArray32.ON );

            Console.WriteLine ( @"{1}    Test # {0} - Default Constructor.{1}" , ++intTestNbr , Environment.NewLine );

            BitArray32 Mask1 = new BitArray32 ( );
			Console.WriteLine ( @"        Initial value of default BitArray32 = {0} (Individual bits: {1})" , Mask1.ToString ( BITMASK_FORMAT_STRING ) , Mask1.ToString ( "B4" ) );

            Mask1.BitOn ( 10 );
			Console.WriteLine ( @"        Bit 10 was turned ON. Mask1 = {0} (Individual bits: {1})" , Mask1.ToString ( BITMASK_FORMAT_STRING ) , Mask1.ToString ( "B4" ) );

            Console.WriteLine ( @"{1}    Test # {0} - First overloaded Constructor.{1}" , ++intTestNbr , Environment.NewLine );

            BitArray32 Mask2 = new BitArray32 ( BitArray32.BIT_07 );

			//	----------------------------------------------------------------
			//	The following statement writes a two-line ruler above the area
			//	where the next three statements will display bit masks. Since
			//	this group prints beneath the ruler, it eschews the spacing in
			//	favor of the compact format that aligns correctly with the
			//	ruler.
			//	----------------------------------------------------------------

			Console.WriteLine (
				"{2}                                                                            {0}{2}                                                                            {1}" ,
				BitArray32.GetRulerTens (
					BitArray32.BitCount.Count32 ,
					BitArray32.BitDisplayOrder.HighBitToLowBit ) ,
				BitArray32.GetRulerUnits (
					BitArray32.BitCount.Count32 ,
					BitArray32.BitDisplayOrder.HighBitToLowBit ) ,
				Environment.NewLine );

			Console.WriteLine ( @"        Initial value of Overloaded BitArray32 = {0} (Individual bits: {1})" , Mask2.ToString ( BITMASK_FORMAT_STRING ) , Mask2.ToString ( "H" ) );

            Mask2.BitOn ( 10 );
			Console.WriteLine ( @"        Bit 10 was turned ON.       Mask2      = {0} (Individual bits: {1})" , Mask2.ToString ( BITMASK_FORMAT_STRING ) , Mask2.ToString ( "H" ) );

            Mask2.BitOff ( 7 );
			Console.WriteLine ( @"        Bit 7 was turned OFF.       Mask2      = {0} (Individual bits: {1})" , Mask2.ToString ( BITMASK_FORMAT_STRING ) , Mask2.ToString ( "H" ) );

            if ( Mask2.IsBitOn ( 10 ) )
                Console.WriteLine ( @"        Bit 10 is ON" );
            else
                Console.WriteLine ( @"        Bit 10 is OFF" );

            if ( Mask2.IsBitOn ( 7 ) )
                Console.WriteLine ( @"        Bit 7 is ON" );
            else
                Console.WriteLine ( @"        Bit 7 is OFF" );

            if ( Mask2.IsBitOff ( 10 ) )
                Console.WriteLine ( @"        Bit 10 is OFF" );
            else
                Console.WriteLine ( @"        Bit 10 is NOT OFF" );

            if ( Mask2.IsBitOff ( 7 ) )
                Console.WriteLine ( @"        Bit 7 is OFF" );
            else
                Console.WriteLine ( @"        Bit 7 is NOT OFF" );

            StreamWriter swReport = null;

            try
            {
                swReport = new StreamWriter (
                    pstrReportFileName ,
                    StandardConstants.FILE_OUT_CREATE ,
                    System.Text.Encoding.ASCII );
                RealWorldTests ( swReport );
            }
            catch ( Exception ex )
            {
                Console.WriteLine ( ex.Message );
            }
            finally
            {   // Clean up the StreamWriter.
                if ( swReport != null )
                {
                    swReport.Close ( );
                    swReport.Dispose ( );
                    swReport = null;
                }   // if ( swReport != null )
            }   // One way or another, the StreamWriter got cleaned up.

            Console.WriteLine (
                "{0}End BitArray32TestStand Exercises{0}" ,
                Environment.NewLine );
        }   // static Exercise method