Calculate() public method

public Calculate ( Combatant, user, Combatant, target ) : float
user Combatant,
target Combatant,
return float
Example #1
0
 private void CalculateFormula()
 {
     Formula.Calculate(Parameters);
     Result     = Formula.Result;
     ResultFull = Formula.ResultFull;
     Formula.FillFormulaTemplate(this);
 }
Example #2
0
        public void GreaterThanFalse()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new GreaterThan <NumericType>(new NumericConstant(100D), new NumericConstant(600D)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance));
        }
Example #3
0
        public void CompositeNotEqualBool()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new NotEqual <BoolType>(new BoolConstant(false), new NotEqual <BoolType>(new BoolConstant(true), new BoolConstant(false))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance));
        }
Example #4
0
        public void SqrtFalse()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Sqrt(new NumericConstant(15D)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance) == 4D);
        }
Example #5
0
        public void GreaterThanOrEqualTrue()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new GreaterThanOrEqual <NumericType>(new NumericConstant(50D), new NumericConstant(50D)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance));
        }
Example #6
0
        public void LessThanOrEqualFalse()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new LessThanOrEqual <NumericType>(new NumericConstant(100D), new NumericConstant(50D)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance));
        }
Example #7
0
        public void BasicAnd()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new And(new BoolConstant(true), new BoolConstant(true)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance));
        }
Example #8
0
        public void Count()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new DataNavigation <NumericType>(nameof(TestDataContext.Subordinates), new Count()),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 3D);
        }
Example #9
0
        public void Min()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new DataNavigation <NumericType>(nameof(TestDataContext.Subordinates), new Min <NumericType>(nameof(Person.RemainingVacation))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 10D);
        }
Example #10
0
        public void Sum()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new DataNavigation <NumericType>(nameof(TestDataContext.Subordinates), new Sum <NumericType>(nameof(Person.Salary))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 122600D);
        }
Example #11
0
        public void Round()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Round(new NumericConstant(9.5698D), 2),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 9.57D);
        }
Example #12
0
        public void CompositeAndEqual()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new And(new Equal <NumericType>(new NumericConstant(3D), new NumericConstant(3D)), new BoolConstant(true)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance));
        }
Example #13
0
        public void Pow()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Pow(new NumericConstant(2D), new NumericConstant(3D)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 8D);
        }
Example #14
0
        public void NegativeBasicOr()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new Or(new BoolConstant(false), new BoolConstant(false)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance));
        }
Example #15
0
        public void Abs()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Abs(new NumericConstant(-10D)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 10D);
        }
Example #16
0
        public void MultiplyFalse()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Multiply(new NumericConstant(20D), new NumericConstant(2D)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance) == 10D);
        }
Example #17
0
        public void AddFalse()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Add <NumericType>(new NumericConstant(9D), new NumericConstant(3D)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance) == 13D);
        }
Example #18
0
        public void Add()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Add <NumericType>(new NumericConstant(15.3D), new NumericConstant(2.5D)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 17.8D);
        }
Example #19
0
        public void RoundFalse()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new Round(new NumericConstant(15.9998D), 3),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance) == 15.999D);
        }
Example #20
0
        public void Concat()
        {
            Formula <string, StringType, TestDataContext> formula = new Formula <string, StringType, TestDataContext>()
            {
                Operations = new DataNavigation <StringType>(nameof(TestDataContext.Subordinates), new Concat(nameof(Person.Name), ";")),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == "Craig;Bennett;Abraham");
        }
Example #21
0
        public void GeoMean()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new DataNavigation <NumericType>(nameof(TestDataContext.Subordinates), new GeometricMean <NumericType>(nameof(Person.RemainingVacation))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 14.658972088782376D);
        }
Example #22
0
        public void CompositeOrEqual()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new Or(new Equal <NumericType>(new NumericConstant(3D), new NumericConstant(5D)),
                                    new GreaterThan <NumericType>(new NumericConstant(5D), new NumericConstant(10D))),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance));
        }
Example #23
0
        public void BasicDataReading()
        {
            // Name of department
            Formula <string, StringType, TestDataContext> formula = new Formula <string, StringType, TestDataContext>()
            {
                Operations = new ReadData <StringType>(nameof(TestDataContext.Department))
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == "IT");
        }
Example #24
0
        public void NavigateAndDataReading()
        {
            // Boss email
            Formula <string, StringType, TestDataContext> formula = new Formula <string, StringType, TestDataContext>()
            {
                Operations = new DataNavigation <StringType>(nameof(TestDataContext.Boss), new ReadData <StringType>(nameof(Person.Email))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == "*****@*****.**");
        }
Example #25
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            int count = grdParameter.RowCount;

            string[] parameters = new string[count];
            for (int i = 0; i < count; i++)
            {
                parameters[i] = grdParameter.Rows[i].Cells[1].Value.ToString();
            }
            txtResult.Text = _formula.Calculate(parameters).ToString();
        }
Example #26
0
        public void StringNumericIfElse()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new IfElse <StringType, NumericType>(new Equal <StringType>(new StringConstant("Value1"), new StringConstant("Value2")),
                                                                  new NumericConstant(10D),
                                                                  new NumericConstant(5D)),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 5D);
        }
Example #27
0
        private void CheckTest <TResult, TPrimitiveType>(Formula <TResult, TPrimitiveType, TestDataContext> formula, string xml, TResult value)
            where TPrimitiveType : BaseType <TResult>
        {
            string formulaXml = Formula <TResult, TPrimitiveType, TestDataContext> .SerializeFormula(formula);

            Assert.IsTrue(string.Compare(formulaXml, xml) == 0);

            Formula <TResult, TPrimitiveType, TestDataContext> deserializedFormula = Formula <TResult, TPrimitiveType, TestDataContext> .DeserializeFormula(formulaXml);

            Assert.IsTrue(value.Equals(deserializedFormula.Calculate(TestDataContext.Instance)));
        }
Example #28
0
        public void SimpleIfElse()
        {
            Formula <bool, BoolType, TestDataContext> formula = new Formula <bool, BoolType, TestDataContext>()
            {
                Operations = new IfElse <NumericType, BoolType>(new Equal <NumericType>(new NumericConstant(3D), new NumericConstant(5D)),
                                                                new BoolConstant(true),
                                                                new BoolConstant(false)),
            };

            Assert.IsFalse(formula.Calculate(TestDataContext.Instance));
        }
Example #29
0
        public void FirstString()
        {
            Formula <string, StringType, TestDataContext> formula = new Formula <string, StringType, TestDataContext>()
            {
                Operations = new DataNavigation <StringType>(nameof(TestDataContext.Subordinates), new Where <NumericType, StringType>(
                                                                 new Equal <NumericType>(new ReadData <NumericType>(nameof(Person.Id)),
                                                                                         new NumericConstant(4D)),
                                                                 new First <StringType>(nameof(Person.Email)))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == "*****@*****.**");
        }
Example #30
0
        public void Where()
        {
            Formula <double, NumericType, TestDataContext> formula = new Formula <double, NumericType, TestDataContext>()
            {
                Operations = new DataNavigation <NumericType>(nameof(TestDataContext.Subordinates), new Where <NumericType, NumericType>(
                                                                  new GreaterThan <NumericType>(new ReadData <NumericType>(nameof(Person.Salary)),
                                                                                                new NumericConstant(40000D)),
                                                                  new Sum <NumericType>(nameof(Person.Salary)))),
            };

            Assert.IsTrue(formula.Calculate(TestDataContext.Instance) == 92600D);
        }