Esempio n. 1
0
        public void ExactlyDivideTest()
        {
            FakeVariableLinker fvl = new FakeVariableLinker();
            DoubleVar          d1  = new DoubleVar(FakeVariableLinker.DoubleA);
            LongVar            i1  = new LongVar(FakeVariableLinker.IntA);
            LongConst          a   = new LongConst(300);
            LongConst          c   = new LongConst(603);
            DoubleConst        b   = new DoubleConst(20.7);

            ArithmeticExpression ae = new ArithmeticExpression(a, i1, Operator.ExactlyDivide);

            Assert.IsTrue(ae.GetResult(fvl).ToString() == "5");
            ae = new ArithmeticExpression(c, a, Operator.ExactlyDivide);
            Assert.IsTrue(ae.GetResult(fvl).ToString() == "2");
            ae = new ArithmeticExpression(c, a, Operator.Divide);
            Assert.IsTrue(ae.GetResult(fvl).ToString() == "2.01");
            ae = new ArithmeticExpression(c, b, Operator.ExactlyDivide);
            Assert.IsTrue(ae.GetResult(fvl).ToString() == "29");
            ae = new ArithmeticExpression(c, a, Operator.Remainder);
            Assert.IsTrue(ae.GetResult(fvl).ToString() == "3");
            ae = new ArithmeticExpression(c, b, Operator.Remainder);
            Assert.IsTrue(ae.GetResult(fvl).ToString() == (603 % 20.7).ToString());
            TestContext.WriteLine(ae.GetResult(fvl).ToString()); // Scan
            ae = new ArithmeticExpression(c, new DoubleConst(0), Operator.Divide);
            Assert.ThrowsException <DivideByZeroException>(() => ae.GetResult(fvl));
            ae = new ArithmeticExpression(c, new DoubleConst(15), Operator.Divide);
            Assert.IsTrue(ae.GetResult(fvl).ToString() == "40.2");

            //TestContext.WriteLine(ae.GetResult(fvl).ToString());
        }
Esempio n. 2
0
        public void JsonSave()
        {
            DoubleVar            d1  = new DoubleVar(FakeVariableLinker.DoubleA);
            LongVar              i1  = new LongVar(FakeVariableLinker.IntA);
            LongConst            a   = new LongConst(300);
            DoubleConst          b   = new DoubleConst(20.7);
            ArithmeticExpression ae  = new ArithmeticExpression(a, i1);
            ArithmeticExpression ae2 = new ArithmeticExpression(ae, d1, Operator.Multiply);
            ArithmeticExpression ae3 = new ArithmeticExpression(ae2, b, Operator.Minus);

            TestContext.WriteLine(JsonConvert.SerializeObject(ae3));
        }
Esempio n. 3
0
        public void VariableAndConst()
        {
            FakeVariableLinker   fvl = new FakeVariableLinker();
            DoubleVar            d1  = new DoubleVar(FakeVariableLinker.DoubleA);
            LongVar              i1  = new LongVar(FakeVariableLinker.IntA);
            LongConst            a   = new LongConst(300);
            DoubleConst          b   = new DoubleConst(20.7);
            ArithmeticExpression ae  = new ArithmeticExpression(a, i1);
            ArithmeticExpression ae2 = new ArithmeticExpression(ae, d1, Operator.Multiply);
            ArithmeticExpression ae3 = new ArithmeticExpression(ae2, b, Operator.Minus);

            Assert.IsTrue(ae3.GetResult(fvl).ToString() == "897.3");
        }
Esempio n. 4
0
            public override object DeepCopy()
            {
                LongVar newVar = new LongVar(_parent);

                copyAttributes(this, newVar);
                newVar._tag    = _tag;
                newVar._parent = _parent;
                if (newVar.Values != null)
                {
                    for (int i = 0; i < newVar.Values.Count; i++)
                    {
                        newVar.Values[i] = (LongVar)Values[i].DeepCopy();
                    }
                }
                return(newVar);
            }