当前位置: 首页>>代码示例>>C#>>正文


C# Formula.Evaluate方法代码示例

本文整理汇总了C#中SpreadsheetUtilities.Formula.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Formula.Evaluate方法的具体用法?C# Formula.Evaluate怎么用?C# Formula.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SpreadsheetUtilities.Formula的用法示例。


在下文中一共展示了Formula.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Cell

 /// <summary>
 /// Constructor for cell with Formula content
 /// Value of this cell is the evaluated content
 /// </summary>
 /// <param name="_name"></param>
 /// <param name="_content"></param>
 /// <param name="lookup"></param>
 public Cell(string _name, Formula _content, Func<string, double> lookup)
 {
     name = _name;
     content = _content;
     value = _content.Evaluate(lookup);
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:13,代码来源:spreadsheet.cs

示例2: Test27

 public void Test27()
 {
     Formula f = new Formula("((((x1+x2)+x3)+x4)+x5)+x6");
     Assert.AreEqual(12.0, f.Evaluate(s => 2));
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:FormulaTester.cs

示例3: Test29

        public void Test29()
        {
        
            Formula f = new Formula("x+7");
            Assert.AreEqual(9.0, f.Evaluate(s => 2));

            Formula f1 = new Formula("x+7", Normalize, Validate);
            Assert.AreEqual(11.0, f.Evaluate(s => 4));
        }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:9,代码来源:FormulaTester.cs

示例4: Test21

 public void Test21()
 {
     Formula f = new Formula("xx");
     Assert.AreEqual(0.0, f.Evaluate(s => 0));
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:FormulaTester.cs

示例5: Test25

 public void Test25()
 {
     Formula f = new Formula("y1*3-8/2+4*(8-9*2)/14*x7");
     Assert.AreEqual(5.142857142, (double)f.Evaluate(s => (s == "x7") ? 1 : 4), 1e-9);
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:FormulaTester.cs

示例6: Test14

 public void Test14()
 {
     Formula f = new Formula("2+(3+5*9)");
     Assert.AreEqual(50.0, f.Evaluate(s => 0));
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:FormulaTester.cs

示例7: Test16

 public void Test16()
 {
     Formula f = new Formula("2+3*5+(3+4*8)*5+2");
     Assert.AreEqual(194.0, f.Evaluate(s => 0));
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:FormulaTester.cs

示例8: Test31

 public void Test31()
 {
     Formula f = new Formula("((((x1+x2)+x3)+x4)+x5)+x6");
     Assert.AreEqual(12, (double)f.Evaluate(s => 2), 1e-9);
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:GradingTests.cs

示例9: Test32

 public void Test32()
 {
     Formula f = new Formula("a4-a4*a4/a4");
     Assert.AreEqual(0, (double)f.Evaluate(s => 3), 1e-9);
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:GradingTests.cs

示例10: myEvaluate

        /// <summary>
        /// Used to get values of direct or indirect dependents
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private object myEvaluate(string name)
        {
            Formula myEval;
            // GetCellContents(name);
            if (GetCellContents(name) is double)
            {
                return (double)mySpreadsheet[name].myValue;
            }
            if (GetCellContents(name) is string)
            {
                return (string)mySpreadsheet[name].myValue;
            }
            if (GetCellContents(name) is Formula)
            {
                Formula myFormula = (Formula)GetCellContents(name);
                string form = myFormula.ToString();
                myEval = new Formula(form, IsValid, Normalize);
                return myEval.Evaluate(myLookup);
            }

            return 0;
        }
开发者ID:HyveMynd,项目名称:CloudSpreadSheet,代码行数:27,代码来源:Spreadsheet.cs

示例11: Test30

 public void Test30()
 {
     Formula f = new Formula("x1+(x2+(x3+(x4+(x5+x6))))");
     Assert.AreEqual(6, (double)f.Evaluate(s => 1), 1e-9);
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:GradingTests.cs

示例12: SetCellContents

        /// <summary>
        /// Takes in a cell name and a formula and returns the dependents
        /// Calculates the value of the formula then recalculates the value of any cell that depends directly or inderectly on it.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="formula"></param>
        /// <returns></returns>
        protected override ISet<string> SetCellContents(string name, Formula formula)
        {
            name = Normalize(name);
            HashSet<string> mySet = new HashSet<string>();
            HashSet<string> replaceSet = new HashSet<string>();

            if (Object.ReferenceEquals(formula, null))
            {
                throw new ArgumentNullException();
            }
            if (Object.ReferenceEquals(name, null))
            {
                throw new InvalidNameException();
            }
            if (!Regex.IsMatch(name, "^([a-z]|[A-Z])+\\d+$") | !IsValid(name))
            {
                throw new InvalidNameException();
            }
            try
            {

                foreach (string s in formula.GetVariables())
                {

                    replaceSet.Add(s);
                }

                // dependentCells.ReplaceDependees(name, mySet);
                dependentCells.ReplaceDependees(name, replaceSet);
                GetCellsToRecalculate(name);
            }
            catch (CircularException)
            {
                throw new CircularException();
            }
            Formula myEvl = new Formula(formula.ToString(), IsValid, Normalize);
            myCell = new Cell(formula, myEvl.Evaluate(myLookup));
            if (mySpreadsheet.ContainsKey(name))
            {
                mySpreadsheet[name] = myCell;
            }
            else
            {
                mySpreadsheet.Add(name, myCell);
            }
            mySet.Add(name);
            foreach (string s in GetCellsToRecalculate(name))
            {
                mySet.Add(s);
            }
            foreach (string s in mySet)
            {
                myCell = new Cell(GetCellContents(s), myEvaluate(s));
                mySpreadsheet[s] = myCell;
            }
            Changed = true;
            return mySet;
        }
开发者ID:HyveMynd,项目名称:CloudSpreadSheet,代码行数:65,代码来源:Spreadsheet.cs

示例13: StressTestMultipleVariables

 public void StressTestMultipleVariables()
 {
     Formula testFormula = new Formula("(3+x)*y", s => s.ToUpper(), s => (s == "X" || s == "Y") ? true : false);
     Func<string, double> lookup = s => (s == "X") ? 1 : 4;
     Assert.AreEqual(16.0, testFormula.Evaluate(lookup));
 }
开发者ID:Buck417,项目名称:First-Half-CS-3500,代码行数:6,代码来源:UnitTest1.cs

示例14: TestEvaluateDivideByZero2

 public void TestEvaluateDivideByZero2()
 {
     Func<string, double> lookup = s => -2;
     Formula testFormula = new Formula("6/(x+2)");
     Object c = testFormula.Evaluate(lookup);
     Assert.AreEqual("SpreadsheetUtilities.FormulaError", c.ToString());
 }
开发者ID:Buck417,项目名称:First-Half-CS-3500,代码行数:7,代码来源:UnitTest1.cs

示例15: Test10

 public void Test10()
 {
     Formula f = new Formula("2+6*3");
     Assert.AreEqual(20.0, f.Evaluate(s => 0));
 }
开发者ID:HeroOfCanton,项目名称:CS3500,代码行数:5,代码来源:FormulaTester.cs


注:本文中的SpreadsheetUtilities.Formula.Evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。