Ejemplo n.º 1
0
        /// <summary>
        /// Applies the current rule to the calculation, by fixing the values on either
        /// left or right hand side of the calculation. The operator will also has the chance
        /// to be changed when applying the rule.
        /// </summary>
        /// <param name="left">The left hand side of the calculation.</param>
        /// <param name="right">The right hand side of the calculation.</param>
        /// <param name="parameters">The calculation generation parameters that are extracted from the equation formation.</param>
        /// <param name="operator">The operator to join the two calculations.</param>
        public void Apply(Calculation left, Calculation right, IDictionary <string, string> parameters, ref Operator @operator)
        {
            if (right == null)
            {
                return;
            }

            if (@operator == Operator.Div &&
                right.Value == 0)
            {
                var max = Convert.ToInt32(parameters["max"]);

                var counter = new ConstantCalculationCounter();
                right.Accept(counter);

                var adjustment = new RandomizedCalculationValueAdjustment(1, max, counter.NumOfConstantCalculations, x => x == 0);
                while (right.Value == 0)
                {
                    adjustment.Reset();
                    right.Accept(adjustment);
                }
            }
        }