public void TestGetVariables1() { Formula f = new Formula("4 + 6 -s + r3 + r3 - t + a5a", IdentityFn, TrueValid); Assert.IsTrue(f.GetVariables().Count == 4); Assert.IsTrue(f.GetVariables().Contains("s")); Assert.IsTrue(f.GetVariables().Contains("r3")); Assert.IsTrue(f.GetVariables().Contains("t")); Assert.IsTrue(f.GetVariables().Contains("a5a")); }
/// <summary> /// Constucts a Formula. /// </summary> /// <param name="f"></param> /// <param name="N"></param> /// <param name="V"></param> public Formula(string f, Normalizer N, Validator V) { //Checks for null input to constuctor. if (f == null || N == null || V == null) { throw new ArgumentNullException("Requires a non-null formula, Normalizer and Validator to constructor."); } Formula newf = new Formula(f); var normvar = new List <string>(); string final = newf.output; //Runs checks on the variables of the formula f when normalized and validated. foreach (string var in newf.GetVariables()) { if (!Regex.IsMatch(N(var), varPattern)) { throw new FormulaFormatException("Normalized variables did not pass standard formula creation requirements for variables."); } if (!V(N(var))) { throw new FormulaFormatException("Normalized variables did not pass Validator test."); } normvar.Add(N(var)); final = final.Replace(var, N(var)); } //Final passing formula is created. Variables = normvar; output = final; }
public void TestGetVariablesEmpty() { Formula f = new Formula(); HashSet <string> vars = (HashSet <string>)f.GetVariables(); Assert.AreEqual(0, vars.Count); }
public void TestGetVariablesNoVariables() { Formula f = new Formula("7 - 3"); HashSet <string> result = (HashSet <string>)f.GetVariables(); Assert.AreEqual(0, result.Count); }
public void GetVars1() { Formula f = new Formula("0"); var expected = new HashSet <string>(); Assert.IsTrue(expected.SetEquals(f.GetVariables())); }
public void GetVars5() { Formula f = new Formula("x+y", s => s.ToUpper(), s => true); var expected = new HashSet <string>(); expected.Add("X"); expected.Add("Y"); Assert.IsTrue(expected.SetEquals(f.GetVariables())); }
public void GetVars6() { Formula f = new Formula("x+y+z", s => s + s, s => true); var expected = new HashSet <string>(); expected.Add("xx"); expected.Add("yy"); expected.Add("zz"); Assert.IsTrue(expected.SetEquals(f.GetVariables())); }
public void Test35() { Formula f = new Formula("a-a*a/a", s => s.ToUpper(), s => (s == s.ToUpper())); foreach (string s in f.GetVariables()) { Assert.AreEqual(s, "A"); } Assert.AreEqual(0, (double)f.Evaluate(s => 3), 1e-9); }
public void GetVars3() { Formula f = new Formula("a * b - c + d / e * 2.5e6"); var expected = new HashSet <string>(); expected.Add("a"); expected.Add("b"); expected.Add("c"); expected.Add("d"); expected.Add("e"); var actual = f.GetVariables(); Assert.IsTrue(expected.SetEquals(actual)); }
public void TestGetVariablesNormalized() { Formula f = new Formula("DUCK - TREE", s => s.ToLower(), s => Char.IsLetter(s[0])); HashSet <string> result = (HashSet <string>)f.GetVariables(); HashSet <string> goal = new HashSet <string>(); goal.Add("duck"); goal.Add("tree"); goal.Add("ham"); foreach (string s in result) { Assert.AreEqual(true, goal.Contains(s)); } }
public void GetVars4() { Formula f = new Formula("a * a + b * c - d * d"); var expected = new HashSet <string>(); expected.Add("a"); expected.Add("b"); expected.Add("c"); expected.Add("d"); var actual = f.GetVariables(); Assert.AreEqual(4, actual.Count); Assert.IsTrue(expected.SetEquals(actual)); }
public void TestGetVariables() { Formula f = new Formula("(duck - tree) / ham"); HashSet <string> result = (HashSet <string>)f.GetVariables(); HashSet <string> goal = new HashSet <string>(); goal.Add("duck"); goal.Add("tree"); goal.Add("ham"); foreach (string s in result) { Assert.AreEqual(true, goal.Contains(s)); } Assert.AreEqual(3, result.Count); }
public void GetVars5() { Formula f = new Formula("x+y", s => s.ToUpper(), s => true); var expected = new HashSet<string>(); expected.Add("X"); expected.Add("Y"); Assert.IsTrue(expected.SetEquals(f.GetVariables())); }
public void TestGetVariablesNorm() { Formula f = new Formula("8", IdentityFn, TrueValid); Assert.IsTrue(f.GetVariables().Count == 0); }
public void GetVars2() { Formula f = new Formula("x"); var expected = new HashSet<string>(); expected.Add("x"); Assert.IsTrue(expected.SetEquals(f.GetVariables())); }
public void GetVars3() { Formula f = new Formula("a * b - c + d / e * 2.5e6"); var expected = new HashSet<string>(); expected.Add("a"); expected.Add("b"); expected.Add("c"); expected.Add("d"); expected.Add("e"); var actual = f.GetVariables(); Assert.IsTrue(expected.SetEquals(actual)); }
public void GetVars4() { Formula f = new Formula("a * a + b * c - d * d"); var expected = new HashSet<string>(); expected.Add("a"); expected.Add("b"); expected.Add("c"); expected.Add("d"); var actual = f.GetVariables(); Assert.AreEqual(4, actual.Count); Assert.IsTrue(expected.SetEquals(actual)); }
public void ZeroArg2() { Formula f = new Formula(); Assert.AreEqual(0, f.GetVariables().Count); }
public void TestGetVariablesZero() { Formula f = new Formula("0"); Assert.IsTrue(f.GetVariables().Count == 0); }
public void GetVars6() { Formula f = new Formula("x+y+z", s => s + s, s => true); var expected = new HashSet<string>(); expected.Add("xx"); expected.Add("yy"); expected.Add("zz"); Assert.IsTrue(expected.SetEquals(f.GetVariables())); }