Exemplo n.º 1
0
        public double Sum(double x, double y)
        {
            var oper   = new SumOperation();
            var result = oper.Exec(new[] { x, y, });

            return(result);
        }
Exemplo n.º 2
0
        public override void Calculation()
        {
            Func <double, double, double> operation;

            switch (_operator)
            {
            case '+':
                operation = new SumOperation(_resultInfo).Execute;
                break;

            case '-':
                operation = new SubtractionOperation(_resultInfo).Execute;
                break;

            case '*':
                operation = new MultiplicationOperation(_resultInfo).Execute;
                break;

            case '/':
                operation = new DivisionOperation(_resultInfo).Execute;
                break;

            default:
                throw new Exception($"Error: Incorrect operation: {_operator}");
            }

            _resultInfo.ResultValue = new SimpleInputDataAnalyzer <TResultInfo>(_resultInfo).Analysis(_firstArgument, _secondArgument, operation).Execute();
        }
Exemplo n.º 3
0
        public void CheckSum()
        {
            SumRequest sum = new SumRequest()
            {
                a = 3, b = 4
            };

            IOperation sumOperation = new SumOperation(_logger, _repositoryMock.Object);

            _repositoryMock.Setup(x => x.Sum(sum.a, sum.b)).Returns(7);

            var result = (SumResponse)sumOperation.Execute(sum);

            Assert.AreEqual(7, result.Result);
        }
Exemplo n.º 4
0
        private void startTheQuiz()
        {
            // Create object to corresponding operation
            sumOperation      = new SumOperation(50, 50, sum);
            minusOperation    = new MinusOperation(50, 50, subtraction);
            divideOperation   = new DivideOperation(50, 50, division);
            multiplyOperation = new MultiplyOperation(50, 50, multiplication);

            // Change labels with question mark to value
            setLabels(plusLeftLabel, plusRightLabel, sumOperation);
            setLabels(minusLeftLabel, minusRightLabel, minusOperation);
            setLabels(divideLeftLabel, divieRightLabel, divideOperation);
            setLabels(timesLeftLabel, timesRightLabel, multiplyOperation);

            // Start the timer
            timeLeft       = 30;
            timeLabel.Text = "30 seconds";
            timer.Start();
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            do
            {
                Console.Clear();
                Matrix.Matrix m1 = new Matrix.Matrix(rnd.Next(3, 7), rnd.Next(3, 7));
                Matrix.Matrix m2 = new Matrix.Matrix(rnd.Next(3, 7), rnd.Next(3, 7));
                Console.WriteLine("m1------");
                Console.WriteLine(m1.ToString());
                Console.WriteLine("m2------");
                Console.WriteLine(m2.ToString());
                MatrixOperation[] operation = new MatrixOperation[rnd.Next(4, 8)];

                for (int i = 0; i < operation.Length; i++)
                {
                    double random = rnd.NextDouble();
                    if (random < 0.33)
                    {
                        operation[i] = new TramsposeOperation();
                    }
                    else
                    {
                        operation[i] = new SumOperation();
                    }
                }
                Console.WriteLine("m2------");
                for (int i = 0; i < operation.Length; i++)
                {
                    Console.WriteLine(operation[i]);
                }
                Matrix.Matrix[] arr = new Matrix.Matrix[operation.Length];

                for (int i = 0; i < operation.Length; i++)
                {
                    try
                    {
                        if (operation[i] is TramsposeOperation)
                        {
                            ((TramsposeOperation)operation[i]).PerformOperation(m1, m2);
                            arr[i] = ((TramsposeOperation)operation[i]).PerformOperation(m1, m2);;
                        }
                        else
                        {
                            arr[i] = ((SumOperation)operation[i]).PerformOperation(m1, m2);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                        continue;
                    }
                }


                Console.WriteLine("Object------");
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i] == null)
                    {
                        continue;
                    }
                    Console.WriteLine(arr[i].ToString());
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
Exemplo n.º 6
0
 public SumNode(NodeContext context, SumOperation operation) : base(context)
 {
     Operation = operation;
 }