Пример #1
0
        static bool TestMismatchedNegativeSymbols(MikesLib.Calculator c, string input = "")
        {
            if (input == "")
            {
                input = "1-,23-,53-,14-,541-,44-,555-";
            }

            double results = c.Add(input, out bool IsError);

            return(PrintTestResult("3", "Mismatching negative symbols", "0", results.ToString(), "True", IsError.ToString()));
        }
Пример #2
0
        static bool TestForZeroInputs(MikesLib.Calculator c, string input = "")
        {
            string ExceptionThrown = "No Exception";
            bool   IsError         = false;
            double result          = 0;

            try
            {
                result = c.Add(input, out IsError);
            }
            catch (ApplicationException ex)
            {
                ExceptionThrown = "ApplicationException";
            }

            return(PrintTestResult("1", "Test for zero inputs", ExceptionThrown, "ApplicationException", "true", IsError.ToString()));
        }
Пример #3
0
        static bool TestForPositiveInput(MikesLib.Calculator c, int amount, bool ExpectedFail, string id)
        {
            Random rnd   = new Random();
            string input = "";
            double total = 0;

            for (int i = 0; i < amount; i++)
            {
                int random = rnd.Next(0, 1000000);
                total += random;
                input += random.ToString();
                if (i != amount - 1)
                {
                    input += ",";
                }
            }
            //Console.WriteLine(input);
            double results = c.Add(input, out bool IsError);

            return(PrintTestResult(id, $"Testing for correction addition for {amount} numbers", results.ToString(), total.ToString(), ExpectedFail.ToString(), IsError.ToString()));
        }
Пример #4
0
        static void Main(string[] args)
        {
            bool allPassed = true;

            if (!TestForZeroInputs(NewCalculator()) |
                !TestMismatchedNegativeSymbols(NewCalculator()) |
                TestForValidInputs())
            {
                ;
            }

            MikesLib.Calculator c = NewCalculator();
            bool   IsError;
            double result  = c.Add("5.22089, 10.9289, 323.2311,-0.38089", out IsError);
            double result2 = c.Add("-5.5, -10.5, -4", out IsError);

            Console.WriteLine("Result = " + result + " " + result2);
            if (!allPassed)
            {
                Console.WriteLine("Some tests failed");
            }
        }