本文整理汇总了C#中SpreadsheetUtilities.Formula类的典型用法代码示例。如果您正苦于以下问题:C# Formula类的具体用法?C# Formula怎么用?C# Formula使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Formula类属于SpreadsheetUtilities命名空间,在下文中一共展示了Formula类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethod1
public void TestMethod1()
{
//stractSpreadsheet sp = new Spreadsheet();
Formula f = new Formula("2+2");
}
示例2: TestEqualsWithNormalizer
public void TestEqualsWithNormalizer()
{
Formula a = new Formula("x1 + x2", VarToUpper, IsValid);
Formula b = new Formula("X1 + X2");
Assert.AreEqual(true, a.Equals(b));
Assert.AreEqual(true, b.Equals(a));
}
示例3: TestEqualsBothNull
public void TestEqualsBothNull()
{
Formula a = new Formula(null);
Formula b = new Formula(null);
Assert.AreEqual(true, a == b);
Assert.AreEqual(true, b == a);
}
示例4: TestNotEqualsBothNull
public void TestNotEqualsBothNull()
{
Formula a = new Formula(null);
Formula b = new Formula(null);
Assert.AreEqual(false, a != b);
Assert.AreEqual(false, b != a);
}
示例5: TestEqualsFromToString
public void TestEqualsFromToString()
{
string expression = "x + 2";
Formula a = new Formula(expression);
Formula b = new Formula(a.ToString());
Assert.AreEqual(true, a.Equals(b));
Assert.AreEqual(true, b.Equals(a));
}
示例6: SetContentsWithFormulaReturnString
public string SetContentsWithFormulaReturnString(AbstractSpreadsheet sheet, string name, Formula formula)
{
List<string> cell_names = new List<string>(sheet.SetCellContents(name, formula));
string[] cell_array = cell_names.ToArray();
string text = string.Join(",", cell_array);
return text;
}
示例7: TestHashCodeTrue
public void TestHashCodeTrue()
{
Formula a = new Formula("2 + X3");
int hashCodeA = a.GetHashCode();
Formula b = new Formula("2+X3");
int hashCodeB = b.GetHashCode();
Assert.AreEqual(hashCodeA, hashCodeB);
}
示例8: Main
static void Main(string[] args)
{
String lpPattern = @"\(";
String rpPattern = @"\)";
String opPattern = @"[\+\-*/]";
String varPattern = @"[a-zA-Z_](?: [a-zA-Z_]|\d)*";
//String doublePattern = @"(?: \d+\.\d* | \d*\.\d+ | \d+ ) (?: [eE][\+-]?\d+)?";
String doublePattern = @"^[0-9\.]*$";
String spacePattern = @"\s+";
// Overall pattern
String pattern = String.Format("({0}) | ({1}) | ({2}) | ({3}) | ({4}) | ({5})",
lpPattern, rpPattern, opPattern, varPattern, doublePattern, spacePattern);
Formula f = new Formula("2.0 + x7 + b6+9- c");
String s = f.GetVariables().ToList().ToString();
Debug.WriteLine(s);
}
示例9: Cell
/// <summary>
/// Creates a cell that has a formula.
/// </summary>
/// <param name="name"></param>
/// <param name="formula"></param>
public Cell(String name, Formula formula)
{
this.name = name;
this.formula = formula;
this.isFormula = true;
}
示例10: SetContentsOfCell
/// <summary>
/// If content is null, throws an ArgumentNullException.
///
/// Otherwise, if name is null or invalid, throws an InvalidNameException.
///
/// Otherwise, if content parses as a double, the contents of the named
/// cell becomes that double.
///
/// Otherwise, if content begins with the character '=', an attempt is made
/// to parse the remainder of content into a Formula f using the Formula
/// constructor. There are then three possibilities:
///
/// (1) If the remainder of content cannot be parsed into a Formula, a
/// SpreadsheetUtilities.FormulaFormatException is thrown.
///
/// (2) Otherwise, if changing the contents of the named cell to be f
/// would cause a circular dependency, a CircularException is thrown.
///
/// (3) Otherwise, the contents of the named cell becomes f.
///
/// Otherwise, the contents of the named cell becomes content.
///
/// If an exception is not thrown, the method returns a set consisting of
/// name plus the names of all other cells whose value depends, directly
/// or indirectly, on the named cell.
///
/// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
/// set {A1, B1, C1} is returned.
/// </summary>
public override ISet<string> SetContentsOfCell(string cell_name, string content)
{
has_changed = true;
string name = Normalize(cell_name);
double number;
if (content == null)
{
throw new ArgumentNullException();
}
else if (name == null || IsValid(name) == false)
{
throw new InvalidNameException();
}
else if (double.TryParse(content, out number))
{
return SetCellContents(name, number);
}
else if (content.StartsWith("=") && content.Length>1)
{
Formula formula;
try
{
string sub_content = content.Substring(1);
formula = new Formula(normalize_function(sub_content, Normalize));
}
catch
{
throw new FormulaFormatException("Invalid Formula");
}
try
{
return SetCellContents(name, formula);
}
catch (Exception)
{
throw new CircularException();
}
}
else if (content.StartsWith("=") && content.Length <= 1)
{
throw new FormulaFormatException("Invalid Fomula");
}
else
{
return SetCellContents(name, content);
}
}
示例11: SetCellContents
/// <summary>
/// An implementation of the abstract method in AbstractSpreadsheet.
/// <seealso cref="AbstractSpreadsheet.SetCellContents(String, Formula)"/>
/// </summary>
/// <param name="name"></param>
/// <param name="formula"></param>
/// <returns></returns>
protected override ISet<String> SetCellContents(String name, Formula formula)
{
// If formula parameter is null, throws an ArgumentNullException.
// Otherwise, if name is null or invalid, throws an InvalidNameException.
name = CorrectInput(name, formula);
formula = NormalizeFormula(formula);
// Otherwise, if changing the contents of the named cell to be the formula would cause a
// circular dependency, throws a CircularException.
IEnumerable<string> previous = dependencies.GetDependees(name);
try
{
dependencies.ReplaceDependees(name, formula.GetVariables());
GetCellsToRecalculate(name);
}
catch (CircularException)
{
dependencies.ReplaceDependees(name, previous);
throw new CircularException();
};
//foreach (string v in formula.GetVariables())
// foreach (string d in GetCellsToRecalculate(v))
// if (name.Equals(d))
// {
// dependencies.ReplaceDependees(name, previous);
// throw new CircularException();
// }
// Otherwise, the contents of the named cell becomes formula.
Changed = true;
GetCell(name).Contents = formula;
// The method returns a Set consisting of name plus the names of all other
// cells whose value depends, directly or indirectly, on the named cell.
return new HashSet<string>(GetCellsToRecalculate(name));
}
示例12: SetContentsOfCell
/// <summary>
/// An implementation of the abstract method in AbstractSpreadsheet.
/// <seealso cref="AbstractSpreadsheet.SetContentsOfCell"/>
/// </summary>
/// <param name="name"></param>
/// <param name="content"></param>
/// <returns></returns>
public override ISet<string> SetContentsOfCell(string name, string content)
{
// Private Variable
ISet<string> set;
// If content is null, throws an ArgumentNullException.
// Otherwise, if name is null or invalid, throws an InvalidNameException.
name = CorrectInput(name, content);
// Otherwise, if content parses as a double, the contents of the named
// cell becomes that double.
double d;
if (Double.TryParse(content, out d))
set = SetCellContents(name, d);
// Otherwise, if content begins with the character '=', an attempt is made
// to parse the remainder of content into a Formula f using the Formula
// constructor.
else if (content.Length > 0 && content[0] == '=')
{
// There are then three possibilities:
// (1) If the remainder of content cannot be parsed into a Formula, a
// SpreadsheetUtilities.FormulaFormatException is thrown.
// Be sure to check the validity of and normalize any variables.
// (2) Otherwise, if changing the contents of the named cell to be f
// would cause a circular dependency, a CircularException is thrown.
Formula f = new Formula(content.Substring(1));
f = NormalizeFormula(f);
try
{
foreach (string v in f.GetVariables())
CorrectInput(v);
}
catch (InvalidNameException)
{
throw new FormulaFormatException(
String.Format("One or more variables in the formula '{0}' contained in cell {1} aren't valid.", f.ToString(), name));
}
// (3) Otherwise, the contents of the named cell becomes f.
set = SetCellContents(name, f);
}
// Otherwise, the contents of the named cell becomes content.
else
set = SetCellContents(name, content);
// Recalculate the values of any cell dependent on the named cell, including the named cell itself.
CalculateCellValues(name);
//Remove any name associations to cell, reset to how it was before the cell was added.
if (content == "")
{
cells.Remove(name);
}
// If an exception is not thrown, the method returns a set consisting of
// name plus the names of all other cells whose value depends, directly
// or indirectly, on the named cell.
// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
// set {A1, B1, C1} is returned.
return set;
}
示例13: TestEquals8
public void TestEquals8()
{
Formula f = new Formula("x7 + 7");
Assert.IsFalse(f == new Formula("2.000 + x7"));
}
示例14: TestEquals6
public void TestEquals6()
{
Formula f = new Formula("x7 + 7");
Assert.IsFalse(f != new Formula("x7 + 7"));
}
示例15: Test28
public void Test28()
{
Formula f = new Formula("a4-a4*a4/a4");
Assert.AreEqual(0.0, f.Evaluate(s => 3));
}