public void SetUp() { _xVariable = new Variable("x"); _yVariable = new Variable("y"); // 2*x + 7*(-y + x) _formulaRoot = new TreeNode<Operator>(OperatorsLibrary.Sum, new TreeNode<Operator>(OperatorsLibrary.Mul, new TreeNode<Operator>(new Constant(2)), new TreeNode<Operator>(_xVariable)), new TreeNode<Operator>(OperatorsLibrary.Mul, new TreeNode<Operator>(new Constant(7)), new TreeNode<Operator>(OperatorsLibrary.Sum, new TreeNode<Operator>(OperatorsLibrary.Minus, new TreeNode<Operator>(_yVariable)), new TreeNode<Operator>(_xVariable)))); }
private static Operator OperatorFromString(string str, ICollection<Variable> availableVariables) { Operator knownOperator = GetKnownOperator(str); if (knownOperator != null) return knownOperator; double constant; if (double.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out constant)) { return new Constant(constant); } Variable availableVariable = availableVariables.FirstOrDefault(op => op.Name == str); if (availableVariable == null) { availableVariable = new Variable(str); availableVariables.Add(availableVariable); } return availableVariable; }
public void TestVariable(double a, double expected) { Variable variable = new Variable("x") { Value = a }; double result = variable.Value; Assert.AreEqual(expected, result); }
public void TestName(string name) { Variable v = new Variable(name); Assert.AreEqual(name, v.Name); }