Пример #1
0
        public void ArithmeticOperatorsDataSet_CoversAllValues()
        {
            // Arrange
            // Get all values in the AllowedArithmeticOperators enum.
            var values = new HashSet <AllowedArithmeticOperators>(
                Enum.GetValues(typeof(AllowedArithmeticOperators)).Cast <AllowedArithmeticOperators>());
            var groupValues = new[]
            {
                AllowedArithmeticOperators.All,
                AllowedArithmeticOperators.None,
            };

            // Act
            // Remove the group items.
            foreach (var allowed in groupValues)
            {
                values.Remove(allowed);
            }

            // Remove the individual items.
            foreach (var allowed in ArithmeticOperators.Select(item => (AllowedArithmeticOperators)(item[0])))
            {
                values.Remove(allowed);
            }

            // Assert
            // Should have nothing left.
            Assert.Empty(values);
        }
Пример #2
0
        private static double GetComputedValue(ArithmeticOperators operators, List <double> numbers)
        {
            Double result = 0;

            switch (operators)
            {
            case ArithmeticOperators.Addition:
                result = numbers.Aggregate((a, x) => a + x);
                break;

            case ArithmeticOperators.Substraction:
                result = numbers.Aggregate((a, x) => a - x);
                break;

            case ArithmeticOperators.Multiplication:
                result = numbers.Aggregate((a, x) => a * x);
                break;

            case ArithmeticOperators.Division:
                result = numbers.Aggregate((a, x) => a / x);
                break;

            default:
                break;
            }

            return(result);
        }
Пример #3
0
 public SmallArithmeticTable(ArithmeticOperators @operator)
 {
     for (int i = 1; i <= 10; i++)
     {
         tasks.AddRange(AllTasksOfTable(@operator, i));
     }
 }
Пример #4
0
 public MathTask(string formula, Dictionary <string, double> variables, string displayValue,
                 ArithmeticOperators op)
 {
     Variables    = variables;
     Formula      = formula;
     Solution     = engine.Calculate(formula, variables);
     DisplayValue = displayValue;
     Operator     = op;
 }
 public static string ToSymbol(this ArithmeticOperators operators)
 {
     return(operators switch
     {
         ArithmeticOperators.Addition => "+",
         ArithmeticOperators.Subtraction => "-",
         ArithmeticOperators.Multiplication => "*",
         ArithmeticOperators.Divison => "/",
         _ => throw new ArgumentOutOfRangeException(nameof(operators), operators, null)
     });
Пример #6
0
        public static void IntervalCalc(int minimum, int maximum, int interval, ArithmeticOperators operators)
        {
            //Check Starting and Ending Number are with in range
            IsWithinRange(minimum, true);
            IsWithinRange(maximum, false);

            //Other mandatory validations
            Validations(minimum, maximum, interval);

            //Build the list of numbers to perform arithmetic operations
            List <double> numbers = GetNumbersToCalculate(minimum, maximum, interval);

            //Perform arithemetic operation
            double result = GetComputedValue(operators, numbers);

            Console.WriteLine("The result is " + result);
            Console.ReadLine();
        }
Пример #7
0
        public ArithmeticTask(int firstArgument, int secondArgument, ArithmeticOperators op)
            : base("a" + op.ToSymbol() + "b",
                   new Dictionary <string, double>()
        {
            { "a", firstArgument },
            { "b", secondArgument }
        }, firstArgument + op.ToDisplaySymbol() + secondArgument, op)
        {
            A         = firstArgument;
            B         = secondArgument;
            Expresion = firstArgument + op.ToSymbol() + secondArgument;
            Meta      = new ArithmeticTaskProperties(this);

            if (op == ArithmeticOperators.Multiplication)
            {
                IsCoreTask = IsCoreTaskNumber(A);
            }
            else if (op == ArithmeticOperators.Divison)
            {
                IsCoreTask = IsCoreTaskNumber((int)Solution) || IsCoreTaskNumber(B);
            }
        }
Пример #8
0
 static void Main(string[] args)
 {
     try
     {
         Console.WriteLine("Enter Starting number for a range between 1 to 1000");
         int minimum = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Enter Ending number for a range between 1 to 1000");
         int maximum = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Provide an interval for cumulative calculation");
         int interval = Convert.ToInt32(Console.ReadLine());
         Console.WriteLine("Choose an arithmetic operation");
         Console.WriteLine("1 for Addtion");
         Console.WriteLine("2 for Substraction");
         Console.WriteLine("3 for Multiplication");
         Console.WriteLine("4 for Division");
         ArithmeticOperators arithmeticOperator = (ArithmeticOperators)(Convert.ToInt32(Console.ReadLine()));
         IntervalCalc(minimum, maximum, interval, arithmeticOperator);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         Console.ReadLine();
     }
 }
Пример #9
0
 public ArithmeticOperation(uint layerIndex, ArithmeticOperators arithmeticOperator)
 {
     LayerIndex = layerIndex;
     Operator   = arithmeticOperator;
 }
Пример #10
0
 public OperatorNode(ArithmeticOperators oper)
 {
     Operator = oper;
 }
Пример #11
0
 private string GetOperatorString(ArithmeticOperators ope) => ope switch
 {
Пример #12
0
 internal string GetOperate1Value(ArithmeticOperators ope, string name1, string value2)
 => JoinItemsWithFormat(Properties.Select(p => p.Name), $"{name1}.{{0}} {GetOperatorString(ope)} {value2}");