示例#1
0
        public void GetDivision_Input26point8and2_Return13point4()
        {
            //Arrange

            double Value1 = 26.8;
            double Value2 = 2;

            double expectedResult = Value1 / Value2;
            Calc1  testCalc1      = new Calc1(Value1, Value2);

            //Act

            double actualResult = testCalc1.GetDivision();

            //Assert

            Assert.AreEqual(expectedResult, actualResult);
        }
示例#2
0
        public void GetDivision_Input2250and90_Return25()
        {
            //Arrange

            double Value1 = 2250;
            double Value2 = 90;

            double expectedResult = Value1 / Value2;
            Calc1  testCalc1      = new Calc1(Value1, Value2);

            //Act

            double actualResult = testCalc1.GetDivision();

            //Assert

            Assert.AreEqual(expectedResult, actualResult);
        }
示例#3
0
        static void Main(string[] args)
        {
            Calc1  c = new Calc1();
            bool   validCalcSelect = false;
            string calcSelection;
            int    selection;

            while (validCalcSelect == false)
            {
                Console.WriteLine("1 = Use random numbers between 0 and 501 for your calculation\n");
                Console.WriteLine("2 = Provide your own numbers\n");
                Console.WriteLine("Choose a menu item to begin:");
                calcSelection = Console.ReadLine();
                Console.WriteLine();

                if (calcSelection != "1" && calcSelection != "2")
                {
                    Console.WriteLine("That's not a valid selection, please try again.\n");
                }
                else if (int.Parse(calcSelection) == 1)
                {
                    validCalcSelect = true;
                    Random random = new Random();
                    double firstNumber;
                    double secondNumber;

                    firstNumber  = Math.Round((random.NextDouble() * 500), 2);
                    secondNumber = Math.Round((random.NextDouble() * 500), 2);

                    Console.WriteLine($"Your random numbers are {firstNumber} and {secondNumber}.\n");
                    Calc1 customCalc = new Calc1(firstNumber, secondNumber);
                    c = customCalc;
                }
                else if (int.Parse(calcSelection) == 2)
                {
                    validCalcSelect = true;

                    double firstNumber;
                    double secondNumber;

                    firstNumber  = ValidateUserInput("firstNumber");
                    secondNumber = ValidateUserInput("secondNumber");

                    Console.WriteLine($"Your custom numbers are {firstNumber} and {secondNumber}.\n");
                    Calc1 customCalc = new Calc1(firstNumber, secondNumber);
                    c = customCalc;
                }
            }


            selection = ValidateMenuSelection();

            while (selection != 9)
            {
                double result;

                switch (selection)
                {
                case 1:
                    Console.WriteLine($"First Number is: {c.GetFirstNumber()}\n");
                    break;

                case 2:
                    result = ValidateUserInput("firstNumber");
                    c.SetFirstNumber(result);
                    break;

                case 3:
                    Console.WriteLine($"Second Number is: {c.GetSecondNumber()}\n");
                    break;

                case 4:
                    result = ValidateUserInput("secondNumber");
                    c.SetSecondNumber(result);
                    break;

                case 5:
                    Console.WriteLine($"The result of {c.GetFirstNumber()} + {c.GetSecondNumber()} is: {c.GetAddition()}\n");
                    break;

                case 6:
                    Console.WriteLine($"The result of {c.GetFirstNumber()} - {c.GetSecondNumber()} is: {c.GetSubtraction()}\n");
                    break;

                case 7:
                    Console.WriteLine($"The result of {c.GetFirstNumber()} * {c.GetSecondNumber()} is: {c.GetMultiplication()}\n");
                    break;

                case 8:
                    Console.WriteLine($"The result of {c.GetFirstNumber()} / {c.GetSecondNumber()} is: {c.GetDivision()}\n");
                    break;

                default:
                    break;
                }

                selection = ValidateMenuSelection();
            }
        }