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);
        }
Пример #2
0
        public void Setting_Wrapped_Sets_Parent_Of_Value()
        {
            var underTest = new ParenthesedExpression {
                Wrapped = new Constant()
            };

            underTest.Wrapped.Parent.Should().BeSameAs(underTest);
        }
Пример #3
0
        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>();
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
        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();
        }
Пример #7
0
 void HandleClosingParenthesis()
 {
     if (mCurrent is IExpressionWithValue)
     {
         mParenthesed.Wrapped = mCurrent;
     }
     mCurrent     = mParenthesed;
     mParenthesed = null;
     if (mCurrent.HasParent)
     {
         FindParentForParentheses();
     }
 }
Пример #8
0
        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);
        }
Пример #9
0
        void FindParentForParentheses()
        {
            var temp = mCurrent;

            while (temp.HasParent)
            {
                temp = temp.Parent;
                if (temp is ParenthesedExpression)
                {
                    mParenthesed = (ParenthesedExpression)temp;
                    break;
                }
                mCurrent = temp;
            }
        }
Пример #10
0
        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;
            }
        }
Пример #11
0
        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);
 }
Пример #14
0
 public void Visit(ParenthesedExpression parenthesed)
 {
     EvaluateParenthesed(parenthesed);
     parenthesed.Wrapped.Accept(this);
 }
Пример #15
0
 protected override IExpression ReplaceParenthesed(ParenthesedExpression parenthesed)
 => parenthesed.Wrapped is Constant ? parenthesed.Wrapped : parenthesed;
 void IExpressionVisitor.Visit(ParenthesedExpression parenthesed)
 {
     Result = UseParenthesed(GetResultFor(parenthesed.Wrapped));
 }
Пример #17
0
 protected virtual void EvaluateParenthesed(ParenthesedExpression parenthesed)
 {
 }
Пример #18
0
 public void Visit(ParenthesedExpression parenthesed)
 {
     mListOfMultipliableExpressions.Add(parenthesed);
 }
Пример #19
0
 protected override void EvaluateParenthesed(ParenthesedExpression parenthesed) => ChangeResultIfTreeDepthIsHigher(parenthesed);
Пример #20
0
 public void SetParent()
 {
     Parent = new ParenthesedExpression();
 }
Пример #21
0
 public void Visit(ParenthesedExpression parenthesed)
 {
     parenthesed.Wrapped.Accept(this);
     mSecondExpressions.Add(parenthesed);
 }
Пример #22
0
 void IExpressionVisitor.Visit(ParenthesedExpression parenthesed) => mResult = ReplaceParenthesed(parenthesed);
Пример #23
0
 protected virtual IExpression ReplaceParenthesed(ParenthesedExpression parenthesed) => parenthesed;
Пример #24
0
 protected override void EvaluateParenthesed(ParenthesedExpression parenthesed) => IncreaseCount();