コード例 #1
0
        internal static int DoTheTests(string [] pastrProgramArgs)
        {
            InitializeTestSelections(pastrProgramArgs);

            try
            {
                if (DoThisTest(CHOICE_MAXSTRINGLENGTH))
                {
                    MaxStringLength_Tests( );
                }

                if (DoThisTest(CHOICE_MERGENEWITEMSINTOARRAY))
                {
                    MergeNewItemsIntoArray_Tests( );
                }

                if (DoThisTest(CHOICE_REPORTDETAILS))
                {
                    ReportDetailsTests(TEST_UNSORTED);
                    ReportDetailsTests(TEST_SORTED);
                }                       // if ( DoThisTest ( CHOICE_REPORTDETAILS ) )

                if (DoThisTest(CHOICE_REPORTHELPERS))
                {
                    ReportHelpersTests( );
                }

                if (DoThisTest(CHOICE_FORMAT_ITEM_GEN))
                {
                    FormatStringParsing_Drills.TestFormatItemBuilders( );
                }

                if (DoThisTest(CHOICE_ASCII_TABLE_GEN))
                {
                    FormatStringParsing_Drills.ASCII_Table_Gen( );
                }

                return(s_fSkipRemainingTests
                                        ? STATUS_SKIP_FURTHER_TESTS
                                        : MagicNumbers.ERROR_SUCCESS);
            }
            catch (Exception exAllKinds)
            {
                Program.s_smTheApp.AppExceptionLogger.ReportException(exAllKinds);
                return(s_fSkipRemainingTests
                                        ? STATUS_SKIP_FURTHER_TESTS
                                        : MagicNumbers.ERROR_RUNTIME);
            }
        }               // DoTheTests
コード例 #2
0
        }           // MergeNewItemsIntoArray_Tests

        private static void ReportDetailsTests(bool pfTestSorting)
        {
            const int OUT_OF_ORDER = 900;

            string strTaskName = System.Reflection.MethodBase.GetCurrentMethod( ).Name;

            Console.WriteLine(
                IDS_MSG_BATCH,
                strTaskName,
                Properties.Resources.IDS_MSG_BEGIN,
                Environment.NewLine);

            if (pfTestSorting)
            {
                FormatStringParsing_Drills.TestFormatItemCounters( );
            }

            ReportDetails rdColl = new ReportDetails( );

            if (pfTestSorting)
            {
                Console.WriteLine(
                    Properties.Resources.MSG_REPORT_DETAILS_SELECTIVELY_OVERRIDDEN,
                    Environment.NewLine);
            }
            else
            {
                Console.WriteLine(
                    Properties.Resources.MSG_REPORT_DETAILS_AUTO_ORDERED,
                    Environment.NewLine);
            }

            rdColl.Add(new ReportDetail(
                           Properties.Resources.IDS_MSG_REPORT_LABEL_1,
                           Properties.Resources.IDS_MSG_REPORT_LABEL_1.Length,
                           Properties.Resources.IDS_MSG_REPORT_LABEL_1.Length.ToString( )));
            rdColl.Add(new ReportDetail(
                           Properties.Resources.IDS_MSG_REPORT_LABEL_2,
                           Properties.Resources.IDS_MSG_REPORT_LABEL_2.Length,
                           Properties.Resources.IDS_MSG_REPORT_LABEL_2.Length.ToString( )));
            rdColl.Add(new ReportDetail(
                           Properties.Resources.IDS_MSG_REPORT_LABEL_3,
                           Properties.Resources.IDS_MSG_REPORT_LABEL_3.Length,
                           Properties.Resources.IDS_MSG_REPORT_LABEL_3.Length.ToString( ),
                           (ReportDetail.ItemDisplayOrder)OUT_OF_ORDER));                                             // This one is intentionally out of order.
            rdColl.Add(new ReportDetail(
                           Properties.Resources.IDS_MSG_REPORT_LABEL_4,
                           Properties.Resources.IDS_REALLY_LONG_STRING.Length));        // Leave the display value NULL.

            Console.WriteLine(
                Properties.Resources.IDS_MSG_LONGEST_LABEL,
                rdColl.WidthOfWidestLabel);
            Console.WriteLine(
                Properties.Resources.IDS_MSG_LONGEST_VALUE,
                rdColl.WidthOfWidestValue,
                Environment.NewLine);

            if (pfTestSorting)
            {               // The sorting pass shows it twice.
                Console.WriteLine(
                    Properties.Resources.MSG_REPORT_DETAILS_UNSORTED,
                    Environment.NewLine);
            }               // if ( pfTestSorting )

            //  ----------------------------------------------------------------
            //  Since the value of this property is computed on demand by
            //  enumerating the collection, it is more efficient to hoist it out
            //  of the loop that also enumerates it. This change improves the
            //  performance of the foreach loop that follows it from an O(n^2)
            //  operation to an O(n) operation.
            //
            //  Since the typical size of these report item collections is on
            //  tho order of a few hundred items or less, the computational
            //  impact of this change is too small to measure without running
            //  hundreds or thousands of iterations. Nevertheless, when it's so
            //  easy to do so, I believe that any operation should be designed
            //  to scale as well as possible.
            //  ----------------------------------------------------------------

            int intWidthOfWidestLabel = rdColl.WidthOfWidestLabel;
            int intWidthOfWidestValue = rdColl.WidthOfWidestValue;

            foreach (ReportDetail rdItem in rdColl)
            {
                Console.WriteLine(
                    ReportDetail.DEFAULT_FORMAT,
                    intWidthOfWidestLabel,
                    rdItem.GetPaddedValue(
                        intWidthOfWidestValue,
                        WizardWrx.FormatStringEngine.FormatItem.Alignment.Right,
                        NumericFormats.DECIMAL));
            }               // foreach ( ReportDetail rdItem in rdColl )

            if (pfTestSorting)
            {               // The second pass follows a sort.
                Console.WriteLine(
                    Properties.Resources.MSG_REPORT_DETAILS_UNSORTED,
                    Environment.NewLine);

                rdColl.Sort( );                     // ReportDetails implements IComparable. Use it.

                foreach (ReportDetail rdItem in rdColl)
                {
                    Console.WriteLine(
                        ReportDetail.DEFAULT_FORMAT,
                        rdItem.GetPaddedLabel(intWidthOfWidestLabel),
                        rdItem.GetPaddedValue(
                            intWidthOfWidestValue,
                            WizardWrx.FormatStringEngine.FormatItem.Alignment.Right,
                            NumericFormats.DECIMAL));
                }           // foreach ( ReportDetail rdItem in rdColl )
            }               // if ( pfTestSorting )

            Console.WriteLine(
                IDS_MSG_BATCH,
                strTaskName,
                Properties.Resources.IDS_MSG_DONE,
                Environment.NewLine);
        }           // private void ReportDetailsTests