Skip to content

Commit

Permalink
#220 - Remove 'DoSimplify' property
Browse files Browse the repository at this point in the history
  • Loading branch information
sys27 committed Jun 2, 2019
1 parent eae0c03 commit 66e20d3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
54 changes: 43 additions & 11 deletions xFunc.Maths/Processor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public Processor()

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

/// <summary>
Expand All @@ -53,8 +52,18 @@ public Processor()
/// <param name="parser">The parser.</param>
/// <param name="simplifier">The simplifier.</param>
/// <param name="differentiator">The differentiator.</param>
public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferentiator differentiator)
: this(lexer, parser, simplifier, differentiator, new TypeAnalyzer(), new ExpressionParameters(AngleMeasurement.Degree, new ParameterCollection(), new FunctionCollection()))
public Processor(
ILexer lexer,
IParser parser,
ISimplifier simplifier,
IDifferentiator differentiator)
: this(
lexer,
parser,
simplifier,
differentiator,
new TypeAnalyzer(),
new ExpressionParameters(AngleMeasurement.Degree, new ParameterCollection(), new FunctionCollection()))
{
}

Expand All @@ -67,7 +76,13 @@ public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferen
/// <param name="differentiator">The differentiator.</param>
/// <param name="typeAnalyzer">The type analyzer.</param>
/// <param name="parameters">The collection of parameters.</param>
public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferentiator differentiator, ITypeAnalyzer typeAnalyzer, ExpressionParameters parameters)
public Processor(
ILexer lexer,
IParser parser,
ISimplifier simplifier,
IDifferentiator differentiator,
ITypeAnalyzer typeAnalyzer,
ExpressionParameters parameters)
{
Lexer = lexer;
Simplifier = simplifier;
Expand All @@ -77,7 +92,6 @@ public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferen

Parameters = parameters;
NumeralSystem = NumeralSystem.Decimal;
DoSimplify = true;
}

/// <summary>
Expand All @@ -86,6 +100,17 @@ public Processor(ILexer lexer, IParser parser, ISimplifier simplifier, IDifferen
/// <param name="function">The function.</param>
/// <returns>The result of solving.</returns>
public IResult Solve(string function)
{
return Solve(function, true);
}

/// <summary>
/// Solves the specified expression.
/// </summary>
/// <param name="function">The function.</param>
/// <param name="simplify">if set to <c>true</c> parser will simplify expression.</param>
/// <returns>The result of solving.</returns>
public IResult Solve(string function, bool simplify)
{
var exp = Parse(function);
exp.Analyze(TypeAnalyzer);
Expand All @@ -112,7 +137,7 @@ public IResult Solve(string function)
}
if (result is IExpression expression)
{
if (DoSimplify)
if (simplify)
return new ExpressionResult(Simplify(expression));

return new ExpressionResult(expression);
Expand All @@ -132,6 +157,18 @@ public IResult Solve(string function)
return (TResult)Solve(function);
}

/// <summary>
/// Solves the specified function.
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <param name="function">The function.</param>
/// <param name="simplify">if set to <c>true</c> parser will simplify expression.</param>
/// <returns>The result of solving.</returns>
public TResult Solve<TResult>(string function, bool simplify) where TResult : IResult
{
return (TResult)Solve(function, simplify);
}

/// <summary>
/// Simplifies the <paramref name="expression"/>.
/// </summary>
Expand Down Expand Up @@ -245,11 +282,6 @@ public IExpression Parse(string function)
/// </value>
public NumeralSystem NumeralSystem { get; set; }

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

}

}
5 changes: 1 addition & 4 deletions xFunc.Tests/ProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ public void ParseBoolTest()
var exp = new Add(Variable.X, new Number(1));
parser.Setup(p => p.Parse(tokens)).Returns(() => exp);

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

lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once());
Expand Down

0 comments on commit 66e20d3

Please sign in to comment.