Пример #1
0
        public static IExpression Subtract(IExpression lhe, IExpression rhe)
        {
            var res = (FlatMultExpression)lhe.Clone();

            if (DimensionKey.Compare(res.DimensionKey, rhe.DimensionKey))
            {
                res.Count.Subtract(rhe.Count);
                return(res);
            }

            return(null);
        }
Пример #2
0
        public static IExpression Add(IExpression lhe, IExpression rhe)
        {
            var res = lhe.Clone();

            if (DimensionKey.Compare(res.DimensionKey, rhe.DimensionKey))
            {
                res.Count.Add(rhe.Count);
                return(res);
            }

            return(null);
        }
Пример #3
0
        public void Clone_FlatMultExpression()
        {
            //Arrange
            var expression = new FlatMultExpression();

            expression.Add(new VariableExpression("x", 1));
            expression.Add(new NumberExpression(3));

            //Act
            var clone = (FlatMultExpression)expression.Clone();

            //Assert
            Assert.IsTrue(DimensionKey.Compare(expression.DimensionKey, clone.DimensionKey));
            Assert.IsTrue(FlatExpression.Compare(expression, clone));
        }
Пример #4
0
        public static IExpression Subtract(IExpression lhe, IExpression rhe)
        {
            var res = lhe.Clone();

            if (rhe is IVariableExpression)
            {
                if (DimensionKey.Compare(res.DimensionKey, rhe.DimensionKey))
                {
                    res.Count.Subtract(rhe.Count);
                    return(res);
                }
            }

            return(null);
        }
Пример #5
0
        public void Clone_FlatAddExpression_Inversed()
        {
            //Arrange
            var flatAdd = new FlatAddExpression();

            flatAdd.Add(new VariableExpression("x", 1));
            flatAdd.Add(new NumberExpression(3));
            var expression = (FlatAddExpression)(new BinaryExpression(flatAdd, OperatorTypes.Power, new NumberExpression(-1)).Execute());

            //Act
            var clone = (FlatAddExpression)expression.Clone();

            //Assert
            Assert.IsTrue(DimensionKey.Compare(expression.DimensionKey, clone.DimensionKey));
            Assert.IsTrue(FlatExpression.Compare(expression, clone));
        }
Пример #6
0
        public static IExpression Add(IExpression lhe, IExpression rhe)
        {
            var res = (FlatMultExpression)lhe.Clone();

            if (DimensionKey.Compare(res.DimensionKey, rhe.DimensionKey))
            {
                //if (res.Expressions.ContainsKey(Dimensions.Number))
                //{
                //    res.Expressions[Dimensions.Number][0].Count.Add(rhe.Count);
                //}
                //else
                //{
                //    res.Count.Add(rhe.Count);
                //}
                res.Count.Add(rhe.Count);
                return(res);
            }

            return(null);
        }
Пример #7
0
        public void Clone_VariableExpression()
        {
            //Arrange
            var expression = new VariableExpression("x", 2);

            expression.Count = new Complex(3, 2);
            expression.DimensionKey.Set("y", 3);

            //Act
            var clone = (VariableExpression)expression.Clone();

            //Assert
            Assert.AreEqual(expression.Symbol, clone.Symbol);
            Assert.IsFalse(Object.ReferenceEquals(expression.Symbol, clone.Symbol));
            Assert.IsTrue(DimensionKey.Compare(expression.DimensionKey, clone.DimensionKey));
            Assert.AreEqual(expression.Count.Re.Numerator, clone.Count.Re.Numerator);
            Assert.AreEqual(expression.Count.Re.Denominator, clone.Count.Re.Denominator);
            Assert.AreEqual(expression.Count.Im.Numerator, clone.Count.Im.Numerator);
            Assert.AreEqual(expression.Count.Im.Denominator, clone.Count.Im.Denominator);
        }