コード例 #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());
        }
コード例 #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));
        }
コード例 #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");
        }
コード例 #4
0
ファイル: DoubleVar.cs プロジェクト: MikeG621/ProjectHex
            public override object DeepCopy()
            {
                DoubleVar newVar = new DoubleVar(_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] = (DoubleVar)Values[i].DeepCopy();
                    }
                }
                return(newVar);
            }
コード例 #5
0
 private void CreateCollectionVariable(List <string> lst, int type)
 {
     for (int i = 0; i < lst.Count; i++)
     {
         if (type == 0)
         {
             BitVar bv = new BitVar("Klapany");
             bv.VarName = lst[i];
             BitValues.Add(bv);
         }
         if (type == 1)
         {
             BoolVar bov = new BoolVar("Klapany");
             bov.VarName = lst[i];
             BoolValues.Add(bov);
         }
         if (type == 2)
         {
             IntVar iv = new IntVar("Klapany");
             iv.VarName = lst[i];
             IntValues.Add(iv);
         }
         if (type == 3)
         {
             DoubleVar dv = new DoubleVar("Klapany");
             dv.VarName = lst[i];
             DoubleValues.Add(dv);
         }
         if (type == 4)
         {
             BoolVarFMS bvfms = new BoolVarFMS("Klapany");
             bvfms.VarName = lst[i];
             BoolFMSValues.Add(bvfms);
         }
     }
 }
コード例 #6
0
ファイル: FSMBehaviour.cs プロジェクト: neoneper/FSMG
 /// <summary>
 /// Procura e retorna em caso de sucesso uma variavel de gráfico do tipo <see cref="DoubleVar"/>
 /// </summary>
 /// <param name="variable">Nome da variavel</param>
 /// <param name="doubleVar">Se encontrado o objeto resultante <see cref="DoubleVar"/> será alocado nele.</param>
 /// <returns>Verdadeiro se encontrado, falso se não encontrado</returns>
 public bool TryGetDoubeValue(string variable, out DoubleVar doubleVar)
 {
     return(doubleVars.TryGetValue(variable, out doubleVar));
 }
コード例 #7
0
 public void ApplyChange(DoubleVar amount)
 {
     value += amount.value;
 }