public void SimpleSquareTest() { var expression = new ParenthesedExpression() { Wrapped = new Addition() { Left = new Power() { Left = new Constant() { Value = 2 }, Right = new Constant() { Value = 2 } }, Right = new Constant() { Value = 16 } } }; mUnderTest.Simplify(expression).Should().BeOfType <ParenthesedExpression>().Which.Wrapped.Should().BeOfType <Addition>().Which.Left.Should().BeOfType <Power>().Which.Left.Should().BeOfType <Constant>().Which.Value.Should().Be(2); mUnderTest.Simplify(expression).Should().BeOfType <ParenthesedExpression>().Which.Wrapped.Should().BeOfType <Addition>().Which.Left.Should().BeOfType <Power>().Which.Right.Should().BeOfType <Constant>().Which.Value.Should().Be(2); mUnderTest.Simplify(expression).Should().BeOfType <ParenthesedExpression>().Which.Wrapped.Should().BeOfType <Addition>().Which.Right.Should().BeOfType <Constant>().Which.Value.Should().Be(16); }
public void Setting_Wrapped_Sets_Parent_Of_Value() { var underTest = new ParenthesedExpression { Wrapped = new Constant() }; underTest.Wrapped.Parent.Should().BeSameAs(underTest); }
public void ReplaceChild_With_Argument_Which_Is_Not_Wrapped_Throws() { var underTest = new ParenthesedExpression { Wrapped = new Constant() }; Action a = () => underTest.ReplaceChild(new Constant(), new Constant()); a.ShouldThrow <ArgumentException>(); }
public void ReplaceChild_Sets_Wrapped_To_NewChild() { var underTest = new ParenthesedExpression { Wrapped = new Constant() }; underTest.ReplaceChild(underTest.Wrapped, new Constant { Value = 13 }); underTest.Wrapped.Should().BeOfType <Constant>().Which.Value.Should().Be(13); }
public void Complex_Case_With_Parenthesed() { var input = new ParenthesedExpression { Wrapped = new Power { Left = new Multiplication { Left = new Constant(), Right = new Constant() }, Right = new Constant() } }; mUnderTest.SetTreeDepth(input); input.Should().BeOfType <ParenthesedExpression>().Which.TreeDepth.Should().Be(0); input.Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Power>() .Which.TreeDepth.Should() .Be(1); input.Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Power>() .Which.Left.Should().BeOfType <Multiplication>().Which.TreeDepth.Should().Be(2); input.Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Power>() .Which.Left.Should() .BeOfType <Multiplication>() .Which.Left.Should() .BeOfType <Constant>() .Which.TreeDepth.Should() .Be(3); input.Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Power>() .Which.Left.Should() .BeOfType <Multiplication>() .Which.Right.Should() .BeOfType <Constant>() .Which.TreeDepth.Should() .Be(3); input.Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Power>() .Which.Right.Should().BeOfType <Constant>().Which.TreeDepth.Should().Be(2); }
public void ReplaceChild_Sets_Parent_Of_OldChild_To_Null() { var oldChild = new Constant(); var underTest = new ParenthesedExpression { Wrapped = oldChild }; underTest.ReplaceChild(underTest.Wrapped, new Constant { Value = 13 }); oldChild.HasParent.Should().BeFalse(); }
void HandleClosingParenthesis() { if (mCurrent is IExpressionWithValue) { mParenthesed.Wrapped = mCurrent; } mCurrent = mParenthesed; mParenthesed = null; if (mCurrent.HasParent) { FindParentForParentheses(); } }
public void ParenthesedZeroBasedMultiplication() { var expression = new ParenthesedExpression { Wrapped = mMultiplicationWithLeftZero }; var result = mZeroRemover.Simplify(expression); result.Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Constant>() .Which.Value.Should() .Be(0M); }
void FindParentForParentheses() { var temp = mCurrent; while (temp.HasParent) { temp = temp.Parent; if (temp is ParenthesedExpression) { mParenthesed = (ParenthesedExpression)temp; break; } mCurrent = temp; } }
void AddNewParenthesesExpression() { var parenthesedExpression = new ParenthesedExpression(); if (mCurrent is ParenthesedExpression) { var parent = (ParenthesedExpression)mCurrent; parent.Wrapped = parenthesedExpression; } mCurrent = parenthesedExpression; mParenthesed = (ParenthesedExpression)mCurrent; if (mCurrentOperation != null) { mCurrentOperation.Right = mCurrent; mWasOpening = true; mCurrentOperation = null; } }
public void Complex_Case() { var input = new ParenthesedExpression() { Wrapped = new Power() { Left = new Multiplication() { Left = new Constant(), Right = new Constant() }, Right = new Constant() } }; mSetter.SetTreeDepth(input); var result = mUnderTest.Evaluate(input); result.Should().Be(3); }
public void ParenthesesSimplifier_Doesnt_Remove_Paretheses_From_Nested_Expressions_With_Operations() { var expression = new ParenthesedExpression { Wrapped = new Addition { Left = new Cosine { Value = 12 }, Right = new Tangent { Value = 12 } } }; mUnderTest.Simplify(expression) .Should() .BeOfType <ParenthesedExpression>() .Which.Wrapped.Should() .BeOfType <Addition>(); }
public void Visit(ParenthesedExpression parenthesed) { parenthesed.Wrapped.Accept(this); }
public void Visit(ParenthesedExpression parenthesed) { EvaluateParenthesed(parenthesed); parenthesed.Wrapped.Accept(this); }
protected override IExpression ReplaceParenthesed(ParenthesedExpression parenthesed) => parenthesed.Wrapped is Constant ? parenthesed.Wrapped : parenthesed;
void IExpressionVisitor.Visit(ParenthesedExpression parenthesed) { Result = UseParenthesed(GetResultFor(parenthesed.Wrapped)); }
protected virtual void EvaluateParenthesed(ParenthesedExpression parenthesed) { }
public void Visit(ParenthesedExpression parenthesed) { mListOfMultipliableExpressions.Add(parenthesed); }
protected override void EvaluateParenthesed(ParenthesedExpression parenthesed) => ChangeResultIfTreeDepthIsHigher(parenthesed);
public void SetParent() { Parent = new ParenthesedExpression(); }
public void Visit(ParenthesedExpression parenthesed) { parenthesed.Wrapped.Accept(this); mSecondExpressions.Add(parenthesed); }
void IExpressionVisitor.Visit(ParenthesedExpression parenthesed) => mResult = ReplaceParenthesed(parenthesed);
protected virtual IExpression ReplaceParenthesed(ParenthesedExpression parenthesed) => parenthesed;
protected override void EvaluateParenthesed(ParenthesedExpression parenthesed) => IncreaseCount();