예제 #1
0
        public void CalculateTest(double firstValue, double secondValue, double expected)
        {
            var calculator   = new Min();
            var actualResult = calculator.Calculate(firstValue, secondValue);

            Assert.AreEqual(expected, actualResult);
        }
예제 #2
0
        public void CalculateAdditionTestStrong(double firstValue, double secondValue, double expected)
        {
            ITwoArgumentsCalculator calculator = new Min();
            double result = calculator.Calculate(25, 2);

            Assert.AreEqual(2, result);
        }
예제 #3
0
        /// <summary>
        /// Вычисление значения переменной
        /// </summary>
        /// <param name="compiler">Объект компилятора выражений</param>
        /// <param name="isEvaluate">Производить вычисление зависимых переменных</param>
        /// <returns>Возврашает истину если вычисление прошло удачно иначе ложь</returns>
        public bool Calculate(Compiler compiler, bool isEvaluate)
        {
            if (Min != null)
            {
                Min.Calculate(compiler, true);
            }
            if (Max != null)
            {
                Max.Calculate(compiler, true);
            }
            if (Step != null)
            {
                Step.Calculate(compiler, true);
            }

            if (isEvaluate == false)
            {
                if (Min != null && Min > Value)
                {
                    Value.Data = Min.Data;
                }
                else if (Max != null && Max < Value)
                {
                    Value.Data = Max.Data;
                }
                else if (Step != null && Min != null)
                {
                    double min  = Convert.ToDouble(Min.Data);
                    double step = Convert.ToDouble(Step.Data);
                    Value.Data = (min + Math.Round((Convert.ToDouble(Value.Data) - min) / step)) * step;
                }
            }

            Value.Calculate(compiler, isEvaluate);

            if (isEvaluate == true)
            {
                if (Min != null && Min > Value)
                {
                    Value.Data = Min.Data;
                    Value.Calculate(compiler, false);
                }
                else if (Max != null && Max < Value)
                {
                    Value.Data = Max.Data;
                    Value.Calculate(compiler, false);
                }
                else if (Step != null && Min != null)
                {
                    double min  = Convert.ToDouble(Min.Data);
                    double step = Convert.ToDouble(Step.Data);
                    Value.Data = (min + Math.Round((Convert.ToDouble(Value.Data) - min) / step)) * step;
                    Value.Calculate(compiler, false);
                }
            }
            return(true);
        }
예제 #4
0
        public void Calcpr(
            double firstElement,
            double secondElement,
            double expected)
        {
            var calculator   = new Min();
            var actualResult = calculator.Calculate(firstElement, secondElement);

            Assert.AreEqual(expected, actualResult);
        }