Exemple #1
0
        public void AddDecimalTest()
        {
            BasicCalculator calc = new BasicCalculator();

            calc.Add(5.5M, 4.5M);
            Assert.AreEqual(10M, calc.Result);
        }
Exemple #2
0
        public void BasicControllerGeneration()
        {
            var calculator = new BasicCalculator(new Addition(), new Subtraction());

            Assert.Equal(3, calculator.Add(2, 1));
            Assert.Equal(1, calculator.Subtract(2, 1));
        }
Exemple #3
0
        public void AddIntTest()
        {
            BasicCalculator calc = new BasicCalculator();

            calc.Add(4, 5);
            Assert.AreEqual(9, calc.Result);
        }
        public void Divide_ByZero_ThrowsDivideByZeroException()
        {
            var calc = new BasicCalculator();

            calc.Add(10);

            Assert.Throws <DivideByZeroException>(() => calc.Divide(0));
        }
Exemple #5
0
        public void AddDecimalArrayTest()
        {
            decimal[]       testArr = { 1.5M, 2.5M, 3.5M };
            BasicCalculator calc    = new BasicCalculator();

            calc.Add(testArr);
            Assert.AreEqual(7.5M, calc.Result);
        }
Exemple #6
0
        public void AddIntArrayTest()
        {
            int[]           testArr = { 1, 2, 3 };
            BasicCalculator calc    = new BasicCalculator();

            calc.Add(testArr);
            Assert.AreEqual(6, calc.Result);
        }
Exemple #7
0
        public void Add_WithValue_ShouldBeAddedToTotal(decimal value, decimal result)
        {
            // Arrange
            var calc = new BasicCalculator();

            // Act
            calc.Add(value);

            // Assert
            Assert.Equal(result, calc.CurrentResult);
        }
        public void Add_WithValue_ShouldAddExpressionToHistory()
        {
            // Arrange
            var     calc  = new BasicCalculator();
            decimal value = 5.0M;

            // Act
            calc.Add(value);

            // Assert
            Assert.Contains("0 + 5.0", calc.History);
        }
        public void Multiply_WithValue_ShouldAddExpressionToHistory()
        {
            // Arrange
            var     calc         = new BasicCalculator();
            decimal starterValue = 5.0M;
            decimal value        = 5.0M;

            // Act
            calc.Add(starterValue);
            calc.Multiply(value);

            // Assert
            Assert.Contains("5.0 * 5.0", calc.History);
        }
        public void Divide_WithValue_ShouldShouldBeDividedFromTotal()
        {
            // Arrange
            var     calc         = new BasicCalculator();
            decimal starterValue = 15.0M;
            decimal value        = 5.0M;

            // Act
            calc.Add(starterValue);
            calc.Divide(value);

            // Assert
            Assert.Equal(3M, calc.CurrentResult);
        }
        public void Multiply_WithValue_ShouldShouldBeMultipliedFromTotal()
        {
            // Arrange
            var     calc         = new BasicCalculator();
            decimal starterValue = 5.0M;
            decimal value        = 5.0M;

            // Act
            calc.Add(starterValue);
            calc.Multiply(value);

            // Assert
            Assert.Equal(25M, calc.CurrentResult);
        }
        public void Divide_WithValue_ShouldAddExpressionToHistory()
        {
            // Arrange
            var     calc         = new BasicCalculator();
            decimal starterValue = 15.0M;
            decimal value        = 5.0M;

            // Act
            calc.Add(starterValue);
            calc.Divide(value);

            // Assert
            Assert.Contains("15.0 / 5.0", calc.History);
        }
        public void MultipleOperations_ShouldKeepRunningTotal_AndAddExpressionsToHistory()
        {
            // Arrange
            var calc = new BasicCalculator();

            calc.Add(5);
            Assert.True(calc.CurrentResult == 5M, "1st Operation CurrentResult");
            Assert.True(calc.History.Count == 1, "1st Operation History Count");

            calc.Multiply(5);
            Assert.True(calc.CurrentResult == 25M, "2nd Operation CurrentResult");
            Assert.True(calc.History.Count == 2, "2nd Operation History Count");

            calc.Subtract(5);
            Assert.True(calc.CurrentResult == 20M, "3rd Operation CurrentResult");
            Assert.True(calc.History.Count == 3, "3rd Operation History Count");

            calc.Divide(4);
            Assert.True(calc.CurrentResult == 5M, "4th Operation CurrentResult");
            Assert.True(calc.History.Count == 4, "4th Operation History Count");
        }
Exemple #14
0
        static void Main(string[] args)
        {
            int             i = 0, j = 0;
            string          a = null, b = null;;
            int             ch         = 0;
            BasicCalculator calculator = null;
            //className refernce = null;
            TempratureConvertor convertor = null;

            convertor  = new TempratureConvertor();
            calculator = new BasicCalculator();

            do
            {
                Console.WriteLine("Menu Driven Program\n");
                Console.WriteLine("0. EXIT\n");
                Console.WriteLine("1. Add\n");
                Console.WriteLine("2. Sub\n");
                Console.WriteLine("3. Mult\n");
                Console.WriteLine("4. Div\n");
                Console.WriteLine("5. fahrenheit to celsius\n");
                Console.WriteLine("6. celsius to fahrenheit \n");
                Console.WriteLine("Enter your choice:");
                string choice = Console.ReadLine();
                ch = Convert.ToInt32(choice);

                switch (ch)
                {
                case 1:
                    Console.WriteLine("Enter the value of a:");
                    a = Console.ReadLine();
                    i = Convert.ToInt32(a);


                    Console.WriteLine("Enter the value of b:");
                    b = Console.ReadLine();
                    j = Convert.ToInt32(b);
                    int res = calculator.Add(i, j);
                    Console.WriteLine("ADDITION :" + res.ToString());
                    break;

                case 2:
                    Console.WriteLine("Enter the value of a:");
                    a = Console.ReadLine();
                    i = Convert.ToInt32(a);


                    Console.WriteLine("Enter the value of b:");
                    b = Console.ReadLine();
                    j = Convert.ToInt32(b);
                    int res1 = calculator.Sub(i, j);
                    Console.WriteLine("SUBSTRACTION :" + res1.ToString());
                    break;

                case 3:
                    Console.WriteLine("Enter the value of a:");
                    a = Console.ReadLine();
                    i = Convert.ToInt32(a);


                    Console.WriteLine("Enter the value of b:");
                    b = Console.ReadLine();
                    j = Convert.ToInt32(b);
                    int res2 = calculator.Mult(i, j);
                    Console.WriteLine("MULTIPLICATION :" + res2.ToString());
                    break;

                case 4:
                    Console.WriteLine("Enter the value of a:");
                    a = Console.ReadLine();
                    i = Convert.ToInt32(a);


                    Console.WriteLine("Enter the value of b:");
                    b = Console.ReadLine();
                    j = Convert.ToInt32(b);
                    int res3 = calculator.Add(i, j);
                    Console.WriteLine("DIVISION :" + res3.ToString());
                    break;

                case 5:

                    Console.WriteLine("Enter the value of fahrenheit :");
                    string  fahrenheit = Console.ReadLine();
                    decimal far        = Convert.ToDecimal(fahrenheit);
                    Decimal res4       = convertor.FarenheitToCelcius(far);
                    Console.WriteLine("Celcius :" + res4.ToString());
                    break;

                case 6:

                    Console.WriteLine("Enter the value of celsius  :");
                    string  celsius = Console.ReadLine();
                    decimal cels    = Convert.ToDecimal(celsius);
                    Decimal res5    = convertor.CelciusToFarenheit(cels);
                    Console.WriteLine("Celcius :" + res5.ToString());
                    break;

                default:
                    Console.Write("Input correct option\n");
                    break;
                }
            } while (ch != 0);
        }
Exemple #15
0
 public void AddTest()
 {
     Assert.AreEqual(12, calc.Add(5, 7));
 }