Skip to content

Commit

Permalink
Fix #170
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Dec 4, 2016
1 parent 492feab commit 1407354
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions SharedCode/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("Release")]
#endif

[assembly: AssemblyVersion("3.2.0")]
[assembly: AssemblyFileVersion("3.2.0")]
[assembly: AssemblyInformationalVersion("3.2.0")]
[assembly: AssemblyVersion("3.2.1")]
[assembly: AssemblyFileVersion("3.2.1")]
[assembly: AssemblyInformationalVersion("3.2.1")]
[assembly: NeutralResourcesLanguage("en")]
28 changes: 12 additions & 16 deletions xFunc.Maths/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public Processor()

parameters = new ExpressionParameters(AngleMeasurement.Degree, new ParameterCollection(), new FunctionCollection());
numeralSystem = NumeralSystem.Decimal;
DoSimplify = true;
}

/// <summary>
Expand Down Expand Up @@ -82,6 +83,7 @@ public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferen

this.parameters = parameters;
this.numeralSystem = NumeralSystem.Decimal;
this.DoSimplify = true;
}

/// <summary>
Expand All @@ -91,7 +93,7 @@ public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferen
/// <returns>The result of solving.</returns>
public IResult Solve(string function)
{
var exp = Parse(function, true);
var exp = Parse(function);
var result = exp.Execute(parameters);
if (result is double)
{
Expand All @@ -114,6 +116,9 @@ public IResult Solve(string function)
}
if (result is IExpression)
{
if (DoSimplify)
return new ExpressionResult(Simplify((IExpression)result));

return new ExpressionResult((IExpression)result);
}

Expand Down Expand Up @@ -181,24 +186,10 @@ public IExpression Differentiate(IExpression expression, Variable variable, Expr
/// </summary>
/// <param name="function">The function.</param>
/// <returns>The parsed expression.</returns>
public IExpression Parse(string function)
{
return Parse(function, true);
}

/// <summary>
/// Parses the specified function.
/// </summary>
/// <param name="function">The function.</param>
/// <param name="simplify">if set to <c>true</c>, simplifies the expression.</param>
/// <returns>The parsed expression.</returns>
/// <exception cref="ArgumentNullException"><paramref name="function"/> is null.</exception>
/// <exception cref="ParserException">Error while parsing.</exception>
public IExpression Parse(string function, bool simplify)
public IExpression Parse(string function)
{
if (simplify)
return simplifier.Simplify(parser.Parse(lexer.Tokenize(function)));

return parser.Parse(lexer.Tokenize(function));
}

Expand Down Expand Up @@ -303,6 +294,11 @@ public NumeralSystem Base
}
}

/// <summary>
/// Gets or sets a value indicating whether do simplify or not.
/// </summary>
public bool DoSimplify { get; set; }

}

}
7 changes: 5 additions & 2 deletions xFunc.Tests/ProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,11 @@ public void ParseBoolTest()
var exp = new Add(new Variable("x"), new Number(1));
parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

var processor = new Processor(lexer.Object, parser.Object, null, null);
var result = processor.Parse("x + 1", false);
var processor = new Processor(lexer.Object, parser.Object, null, null)
{
DoSimplify = false
};
var result = processor.Parse("x + 1");

lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once());
Expand Down

0 comments on commit 1407354

Please sign in to comment.