本文整理汇总了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);
}
示例2: Test27
public void Test27()
{
Formula f = new Formula("((((x1+x2)+x3)+x4)+x5)+x6");
Assert.AreEqual(12.0, f.Evaluate(s => 2));
}
示例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));
}
示例4: Test21
public void Test21()
{
Formula f = new Formula("xx");
Assert.AreEqual(0.0, f.Evaluate(s => 0));
}
示例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);
}
示例6: Test14
public void Test14()
{
Formula f = new Formula("2+(3+5*9)");
Assert.AreEqual(50.0, f.Evaluate(s => 0));
}
示例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));
}
示例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);
}
示例9: Test32
public void Test32()
{
Formula f = new Formula("a4-a4*a4/a4");
Assert.AreEqual(0, (double)f.Evaluate(s => 3), 1e-9);
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
示例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());
}
示例15: Test10
public void Test10()
{
Formula f = new Formula("2+6*3");
Assert.AreEqual(20.0, f.Evaluate(s => 0));
}