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)); }
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)); }
public void EqualsTest2() { Formula f1 = new Formula("2+3"); Formula f2 = new Formula("2+4"); Assert.IsFalse(f1.Equals(f2)); }
public void EqualsOnNegativeScientificNotation() { Formula f = new Formula("5e-4"); Formula g = new Formula("0.0005"); Assert.IsTrue(f.Equals(g)); }
public void EqualsTest() { Formula f1 = new Formula("2+3"); Formula f2 = new Formula("2+3"); Assert.IsTrue(f1.Equals(f2)); }
public void TestEquals() { Formula one = new Formula("x1+y2", Normalize, Validate); Assert.IsTrue(one.Equals(new Formula("X1+Y2"))); }
public void TestEquals3() { Formula three = new Formula("x1+y2"); Assert.IsFalse(three.Equals(new Formula("y2+x1"))); }
public void Test35() { Formula f1 = new Formula("2+X1*3.00"); Formula f2 = new Formula("2.00+X1*3.0"); Assert.IsTrue(f1.Equals(f2)); }
public void Test37() { Formula f = new Formula("2"); Assert.IsFalse(f.Equals(null)); Assert.IsFalse(f.Equals("")); }
/// <summary> /// If the formula parameter is null, throws an ArgumentNullException. /// /// Otherwise, if name is null or invalid, throws an InvalidNameException. /// /// Otherwise, if changing the contents of the named cell to be the formula would cause a /// circular dependency, throws a CircularException. (No change is made to the spreadsheet.) /// /// Otherwise, the contents of the named cell becomes 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. /// /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the /// set {A1, B1, C1} is returned. /// </summary> protected override ISet<string> SetCellContents(string name, Formula formula) { // If the formula parameter is null, throws an ArgumentNullException. if (formula.Equals(null)) { throw new ArgumentNullException(); } // Otherwise, if name is null or invalid, throws an InvalidNameException. if (!Cell.validName(name) || !IsValid(name)) { throw new InvalidNameException(); } // If cell doesn't exist, add it if (!allCells.ContainsKey(name)) { // add new cell allCells.Add(name, new Cell(name, formula, Lookup)); // if formula contained variables, setup new dependencies if (formula.GetVariables().Count() > 0) { foreach (string str in formula.GetVariables()) { graph.AddDependency(name, str); } } HashSet<string> dependents = new HashSet<string>(); List<string> dependentCells = GetCellsToRecalculate(name).ToList(); dependents.Add(name); foreach (string str in dependentCells) { allCells[str].eval(Lookup); dependents.Add(str); } return dependents; } // Otherwise, if changing the contents of the named cell to be the formula would cause a // circular dependency, throws a CircularException. (No change is made to the spreadsheet.) GetCellsToRecalculate(name); // Otherwise, the contents of the named cell becomes formula. // If cell exists, overwrite it's content Cell temp; if (allCells.TryGetValue(name, out temp)) { temp.setContents(formula); } // If the replacement formula has variables, replace the dependency of the old cell with // new ones from the new formula. if (formula.GetVariables().Count() > 0) { List<string> variables = new List<string>(); foreach (string str in formula.GetVariables()) { variables.Add(str); } graph.ReplaceDependents(name, variables); } // Get all dependents, indirect and direct, and then add them to a List which is then // added to the returned HashSet HashSet<string> dependent = new HashSet<string>(); List<string> dependentCell = GetCellsToRecalculate(name).ToList(); dependent.Add(name); foreach (string str in dependentCell) { allCells[str].eval(Lookup); dependent.Add(str); } return dependent; }
public void TestEqualsSameObjectType() { Formula testFormula1 = new Formula("a/b"); Formula testFormula2 = new Formula("a/b"); Assert.IsTrue(testFormula1.Equals(testFormula2)); }
public void TestNotEqualsSameResult() { Formula a = new Formula("2 + 3 + 1"); Formula b = new Formula("5 + 1"); Assert.AreEqual(false, a.Equals(b)); Assert.AreEqual(false, b.Equals(a)); }
public void TestEqualsNotAnObject() { Formula f = new Formula("2 + 3"); Assert.AreEqual(false, f.Equals(new Object())); Assert.AreEqual(false, f.Equals("Hi there")); }
public void TestNotEqualsReversedExpressions() { Formula a = new Formula("a + b"); Formula b = new Formula("b + a"); Assert.AreEqual(false, a.Equals(b)); Assert.AreEqual(false, b.Equals(a)); }
public void TestEqualsWithPrecision() { Formula a = new Formula("2.0"); Formula b = new Formula("2.0000"); Assert.AreEqual(true, a.Equals(b)); Assert.AreEqual(true, b.Equals(a)); }
public void TestEquals() { Formula a = new Formula("x + y2"); Formula b = new Formula("x+y2"); Assert.AreEqual(true, a.Equals(b)); Assert.AreEqual(true, b.Equals(a)); }
public void EqualsOnUpperNormalizerFalse() { Formula f = new Formula("y1*3-8/2+4/(8-9*2)/14*X7"); Formula g = new Formula("y1*3-8/2+4/(8-9*2)/14*x7", s => s.ToUpper(), s => true); Assert.IsFalse(f.Equals(g)); }
public void EqualsOnPositiveScientificNotation() { Formula f = new Formula("5e4"); Formula g = new Formula("50000"); Assert.IsTrue(f.Equals(g)); }
public void ToStringTest() { Formula testFormula = new Formula("4+35"); Assert.IsTrue(testFormula.Equals(new Formula(testFormula.ToString()))); }
public void PublicEqualsNormalizationTest() { Formula f1 = new Formula("5+3e+2"); Formula f2 = new Formula("5+3E+2"); Assert.AreEqual(true, f1.Equals(f2)); Assert.AreEqual(305.0, f1.Evaluate(getVariable)); Assert.AreEqual(305.0, f2.Evaluate(getVariable)); }
public void Test34() { Formula f1 = new Formula("X1+X2"); Formula f2 = new Formula(" X1 + X2 "); Assert.IsTrue(f1.Equals(f2)); }
public void PublicEqualsPrecisionTest1() { Formula f1 = new Formula("5+.00000000000000000000001"); Formula f2 = new Formula("5+.001"); Assert.AreEqual(false, f1.Equals(f2)); }
public void Test36() { Formula f1 = new Formula("1e-2 + X5 + 17.00 * 19 "); Formula f2 = new Formula(" 0.0100 + X5+ 17 * 19.00000 "); Assert.IsTrue(f1.Equals(f2)); }
public void PublicEqualsPrecisionTest2() { Formula f1 = new Formula("5+.00000000000000000000001"); Formula f2 = new Formula("5+1e-23"); Assert.AreEqual(true, f1.Equals(f2)); }
public void Test43() { Formula f = new Formula("2*5"); Assert.IsTrue(f.Equals(new Formula(f.ToString()))); }
public void PublicEqualsTest() { Formula f1 = new Formula("5+A1"); Formula f2 = new Formula("5+A1"); Assert.AreEqual(true, f1.Equals(f2)); }
public void TestEquals2() { Formula two = new Formula("x1+y2"); Assert.IsFalse(two.Equals(new Formula("X1+Y2"))); }
public void PublicEqualsTest1() { Formula f1 = new Formula("5+A1"); Formula f2 = null; Assert.AreEqual(false, f1.Equals(f2)); }
public void TestEquals4() { Formula four = new Formula("2.0 + x7"); Assert.IsTrue(four.Equals(new Formula("2.000 + x7"))); }
public void EqualsOnDuplicateString() { Formula f = new Formula("y1*3-8/2+4/(8-9*2)/14*x7"); Formula g = new Formula("y1*3-8/2+4/(8-9*2)/14*x7"); Assert.IsTrue(f.Equals(g)); }