Ejemplo n.º 1
0
    public static void Show()
    {
        string[] args = new string[] { "3", "5" };

        Console.WriteLine("Function Client");

        if (args.Length == 0)
        {
            Console.WriteLine("Usage: FunctionTest ... ");
            return;
        }

        for (int i = 0; i < args.Length; i++)
        {
            int num = Int32.Parse(args[i]);
            Console.WriteLine(
                "The Digit Count for String [{0}] is [{1}]",
                args[i],
                // 调用 DigitCount 类中的
                // NumberOfDigits 静态方法:
                DigitCount.NumberOfDigits(args[i]));
            Console.WriteLine(
                "The Factorial for [{0}] is [{1}]",
                num,
                // 调用 Factorial 类中的 Calc 静态方法:
                Factorial.Calc(num));
        }
    }
Ejemplo n.º 2
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Function Client");

        if (args.Length == 0)
        {
            Console.WriteLine("Usage: FunctionTest ... ");
            return;
        }

        for (int i = 0; i < args.Length; i++)
        {
            int num = Int32.Parse(args[i]);
            Console.WriteLine(
                "The Digit Count for String [{0}] is [{1}]",
                args[i],
                // Вызов статического метода NumberOfDigits
                // класса DigitCount:
                DigitCount.NumberOfDigits(args[i]));
            Console.WriteLine(
                "The Factorial for [{0}] is [{1}]",
                num,
                // Вызов статического метода Calc класса Factorial:
                Factorial.Calc(num));
        }
    }
Ejemplo n.º 3
0
 public void FactorialGoodInput()
 {
     for (int i = 0; i < correctFacts.Length; ++i)
     {
         Assert.AreEqual(Factorial.Calc(i), correctFacts[i]);
     }
 }
Ejemplo n.º 4
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Function Client");

        if (args.Length == 0)
        {
            Console.WriteLine("Usage: FunctionTest ... ");
            return;
        }

        for (int i = 0; i < args.Length; i++)
        {
            int num = Int32.Parse(args[i]);
            Console.WriteLine(
                "The Digit Count for String [{0}] is [{1}]",
                args[i],
                // Invoke the NumberOfDigits static method in the
                // DigitCount class:
                DigitCount.NumberOfDigits(args[i]));
            Console.WriteLine(
                "The Factorial for [{0}] is [{1}]",
                num,
                // Invoke the Calc static method in the Factorial class:
                Factorial.Calc(num));
        }
    }
Ejemplo n.º 5
0
        public void Calc_WhenvalidInPutLarge()
        {
            // arrange
            int test     = 12;
            int expected = 479001600;

            Factorial.Calc(test);

            int actual = Factorial.GetCalcResult;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 6
0
        public void Calc_WhenValidInPut()
        {
            // arrange
            int test     = 5;
            int expected = 120;

            Factorial.Calc(test);

            int actual = Factorial.GetCalcResult;

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
    public static void Main(string[] args)
    {
        int extractedNumberFromString;

        Console.WriteLine("Function Client\n===============\n");

        if (args.Length == 0)
        {
            Console.WriteLine("Usage: FunctionTest <test string> ");
            return;
        }

        for (int i = 0; i < args.Length; i++)
        {
            // analyze the incoming "test string" to determine what types of
            // characters are present ...
            //
            // first - how many digits are found within the string ...
            Console.WriteLine("The Digit Count for String [{0}] is [{1}]", args[i], StringBreakout.NumberOfDigits(args[i]));

            //
            // next  - how many alphabetic characters are found within the string ...
            Console.WriteLine("The Alpha Count for String [{0}] is [{1}]", args[i], StringBreakout.NumberOfAlphas(args[i]));

            //
            // lastly - determine the number of non-digit / non-alpha characters
            Console.WriteLine("The Other Count for String [{0}] is [{1}]", args[i], StringBreakout.NumberOfOthers(args[i]));

            // next function to call is to extract the number(s) from the string and use it to determine
            // its factorial !
            //
            // *************************************************************************************************
            // the code below assumes that the argv[i] string *only* contains digits.  I want you to write
            // another class method in the StringBreakout class to detect and extract the numbers hidden in
            // the incoming string and use that number in the factorial calculation
            //    for example, if the incoming string is Char1i3  <<< yes there is a "1" and "3" in that string
            //                 then the method you write would find the "1" and the "3" and return the value
            //                 13
            //    this new method should look like :
            //                 int FindAndExtractDigits(string theString)
            // *************************************************************************************************
            try
            {
                extractedNumberFromString = Int32.Parse(args[i]);
                Console.WriteLine("   >>> {0}! = {1}", extractedNumberFromString, Factorial.Calc(extractedNumberFromString));
            }
            catch (FormatException e)
            {
                Console.WriteLine("   >>> String contained no digits ...");
            }
        }
    }
Ejemplo n.º 8
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Function Client");

        if (args.Length == 0)
        {
            Console.WriteLine("Usage: FunctionTest ...");
            return;
        }
        for (int i = 0; i < args.Length; i++)
        {
            int num = Int32.Parse(args[i]);
            Console.WriteLine(
                "The digit count from string [{0}] is [{1}]",
                args[i], DigitCount.NumberOfDigits(args[i]));
            Console.WriteLine(
                "The Factorial for [{0}] is [{1}]",
                num, Factorial.Calc(num));
        }
    }
Ejemplo n.º 9
0
 public void FactorialOverFlow()
 {
     Factorial.Calc(correctFacts.Length);
 }
Ejemplo n.º 10
0
 public void FactorialNegative()
 {
     Factorial.Calc(-1);
 }