Ejemplo n.º 1
0
        public void TestAddition()
        {
            Calculator.models.Calculator calc = new Calculator.models.Calculator();
            decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.ADDITION);

            Assert.Equal(10.0m, result);
        }
Ejemplo n.º 2
0
        public void TestDivision()
        {
            Calculator.models.Calculator calc = new Calculator.models.Calculator();
            decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.DIVISTION);

            Assert.Equal(3.0m, result);
        }
Ejemplo n.º 3
0
        public void TestMultiplikation()
        {
            Calculator.models.Calculator calc = new Calculator.models.Calculator();
            decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.MULTIPLICATION);

            Assert.Equal(18.75m, result);
        }
Ejemplo n.º 4
0
        public void TestSubtraktion()
        {
            Calculator.models.Calculator calc = new Calculator.models.Calculator();
            decimal result = calc.Calculate(7.5m, 2.5m, CalculationType.SUBTRACTION);

            Assert.Equal(5.0m, result);
        }
        static void Main(string[] args)
        {
            var isRunning = true;

            models.Calculator calc = new models.Calculator();

            Console.WriteLine("welcome to our calculator");

            while (isRunning)
            {
                Console.WriteLine("Start your calculation.");
                Console.WriteLine("number 1:");
                string number1Input = Console.ReadLine();
                Console.WriteLine("number 2:");
                string number2Input = Console.ReadLine();
                Console.WriteLine("operation:");
                string operation = Console.ReadLine();

                decimal.TryParse(number1Input, out var number1);
                decimal.TryParse(number2Input, out var number2);

                CalculationType?calculationType = null;

                switch (operation)
                {
                case "+":
                    calculationType = CalculationType.ADDITION;
                    break;

                case "-":
                    calculationType = CalculationType.SUBTRACTION;
                    break;

                case "*":
                    calculationType = CalculationType.MULTIPLICATION;
                    break;

                case "/":
                    calculationType = CalculationType.DIVISTION;
                    break;
                }

                if (calculationType.HasValue)
                {
                    Console.WriteLine(calc.Calculate(number1, number2, calculationType.Value));
                }

                Console.WriteLine("Do you want to continue? y/n");
                string choice = Console.ReadLine();

                if (choice.ToLower().Equals("n"))
                {
                    isRunning = false;
                }
            }
        }
Ejemplo n.º 6
0
        public void Model_multiply_CommonMultiplication_1()
        {
            // Arrange
            Calculator.models.Calculator calculator = new Calculator.models.Calculator();
            double expected = 169;
            // Act
            double result = calculator.multiply(13, 13);

            // Assert
            Assert.AreEqual <double>(expected, result);
        }
Ejemplo n.º 7
0
        public void Model_divide_CommonDividion_1()
        {
            // Arrange
            Calculator.models.Calculator calculator = new Calculator.models.Calculator();
            double expected = 3.25;
            // Act
            double result = calculator.divide(13, 4);

            // Assert
            Assert.AreEqual <double>(expected, result);
        }
Ejemplo n.º 8
0
        public void Model_sum_CommonSum_1()
        {
            // Arrange
            Calculator.models.Calculator calculator = new Calculator.models.Calculator();
            double expected = 228;
            // Act
            double result = calculator.sum(200, 28);

            // Assert
            Assert.AreEqual <double>(expected, result);
        }
Ejemplo n.º 9
0
        public void Model_subtract_CommonSubtracttion_1()
        {
            // Arrange
            Calculator.models.Calculator calculator = new Calculator.models.Calculator();
            double expected = -25;
            // Act
            double result = calculator.subtract(150, 175);

            // Assert
            Assert.AreEqual <double>(expected, result);
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine(Enum.GetName(typeof(CalculationType), CalculationType.ADDITION));
            models.Calculator calc = new models.Calculator();

            Console.WriteLine("Welcome to our calculator");
            Console.WriteLine("Number 1:");
            string number1Input = Console.ReadLine();

            Console.WriteLine("Number 2:");
            string number2Input = Console.ReadLine();

            Console.WriteLine("Operation (-,+,*,/):");
            string operation = Console.ReadLine();

            decimal.TryParse(number1Input, out var number1);
            decimal.TryParse(number2Input, out var number2);

            CalculationType?calculationType = null;


            switch (operation)
            {
            case "+":
                calculationType = CalculationType.ADDITION;
                break;

            case "-":
                calculationType = CalculationType.SUBTRACTION;
                break;

            case "*":
                calculationType = CalculationType.MULTIPLICATION;
                break;

            case "/":
                calculationType = CalculationType.DIVISTION;
                break;
            }

            if (calculationType.HasValue)
            {
                Console.WriteLine(calc.Calculate(number1, number2, calculationType.Value));
            }
        }