public Token(Parser.ValType ivType, string isValue) { vType = ivType; sValue = isValue; if (vType == Parser.ValType.NUMBER) { if(sValue.Equals("PI")) dValue = Math.PI; else dValue =Parser.stringToDouble(sValue); } }
public void parseFunctionTest() { //test setup Parser target = new Parser(); // TODO: Initialize to an appropriate value string function = " x*6*x "; // TODO: Initialize to an appropriate value List<Token> expected = new List<Token>(); // TODO: Initialize to an appropriate value List<Token> actual = new List<Token>(); expected.Add(new Token(Parser.ValType.VARIABLE,"X")); expected.Add(new Token(Parser.ValType.OPtd, "*")); expected.Add(new Token(Parser.ValType.NUMBER, "6")); expected.Add(new Token(Parser.ValType.OPtd, "*")); expected.Add(new Token(Parser.ValType.VARIABLE, "X")); //test method try { actual = target.parseFunction(function); } catch (InvalidInputException ex) { Assert.Fail(ex.Message); } //show output StringBuilder output = new StringBuilder(); foreach (Token str in actual) { output.Append(str.ToString()); output.Append("_"); } Console.Write(output.ToString()); //verify output if (expected.Count != actual.Count) Assert.Fail("Input and Output are different lengths"); for (int i = 0; i < expected.Count; i++) { if (!expected[i].isEqual(actual[i])) Assert.Fail("Values not equal at" + i); } Assert.IsTrue(true); //Assert.Inconclusive("Verify the correctness of this test method."); }
//check for function validity before constructing public Function(string inputFuncion, string from, string to, string increments) { this.functionStr = inputFuncion; this.from = double.Parse(from); this.to = double.Parse(to); this.increments = double.Parse(increments); //how many inputs to function are needed int numberOfInputs = (int)Math.Abs((this.from - this.to) / this.increments)+1; inputs = new double[numberOfInputs]; outputs = new double[numberOfInputs]; //parse that fucntion fParser = new Parser(); fParser.inputFuntion(functionStr); //calculate values for (int i = 0; i < numberOfInputs; i++) { outputs[i] = fParser.evalFuncAt(this.from + this.increments * i); } }