public void ExecutarExpressaoSimples()
        {
            int a=1, b=2;
            string expressao = "(a+b)>0";
            string blocoAcaoTrue = "a=0;b=-1";
            string blocoAcaoFalse = "a=-1;b=0";

            InequationEngine maquinaInequacoes = new InequationEngine();
            maquinaInequacoes.CalculationMemory.Add(new Variable("a", VariableDataType.Numeric, a));
            maquinaInequacoes.CalculationMemory.Add(new Variable("b", VariableDataType.Numeric, b));

            Inequation inequacao = new Inequation(expressao);
            ActionBlock blocoAcaoTrueObj = new ActionBlock(blocoAcaoTrue);
            ActionBlock blocoAcaoFalseObj = new ActionBlock(blocoAcaoFalse);

            Decision decisao = new Decision(inequacao, blocoAcaoTrueObj, blocoAcaoFalseObj);
            maquinaInequacoes.DecisionsList.AddDecision(decisao);

            maquinaInequacoes.Compile();

            maquinaInequacoes.Execute();

            Assert.AreEqual(maquinaInequacoes.CalculationMemory["a"].GetValue(), 0.0);
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["b"].GetValue(), -1.0);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Método para popular a decisão com {inequação, bloco V}. Bloco F = vazio.
        /// </summary>
        /// <param name="maquinaInequacoes"></param>
        /// <param name="decisaoLinha"></param>
        public void AtualizarListaDeDecisoes(InequationEngine maquinaInequacoes, KeyValuePair<string, string> decisaoLinha)
        {
            Inequation inequacao = new Inequation(decisaoLinha.Key);
            ActionBlock blocoAcaoTrueObj = new ActionBlock(decisaoLinha.Value);
            ActionBlock blocoAcaoFalseObj = new ActionBlock(string.Empty);

            Decision decisao = new Decision(inequacao, blocoAcaoTrueObj, blocoAcaoFalseObj);
            maquinaInequacoes.DecisionsList.AddDecision(decisao);
        }
        public void ExecutarOperacaoComparacaoHora()
        {
            string pattern = "HH:mm:ss";
            string horaA = "20:27:31";
            string horaB = "20:09:50";
            DateTime a = DateTime.Now;
            DateTime b = DateTime.Now;
            double result = double.MinValue;
            DateTime horaConvertidaFlee = DateTime.Now;

            // Testa a maior que b
            string expressao = "(a>b)";
            string blocoAcaoTrue = "result=100;";
            string blocoAcaoFalse = "result=0;";

            if (!DateTime.TryParseExact(horaA, pattern, null, System.Globalization.DateTimeStyles.None, out a) || !DateTime.TryParseExact(horaB, pattern, null, System.Globalization.DateTimeStyles.None, out b))
            {
                throw new Exception("Erro no parsing das variáveis de hora.");
            }

            InequationEngine maquinaInequacoes = new InequationEngine();
            maquinaInequacoes.CalculationMemory.Add(new Variable("a", VariableDataType.Time, a));
            maquinaInequacoes.CalculationMemory.Add(new Variable("b", VariableDataType.Time, b));
            maquinaInequacoes.CalculationMemory.Add(new Variable("result", VariableDataType.Numeric, result));
            maquinaInequacoes.CalculationMemory.Add(new Variable("horaA", VariableDataType.String, horaA));

            Inequation inequacao = new Inequation(expressao);
            ActionBlock blocoAcaoTrueObj = new ActionBlock(blocoAcaoTrue);
            ActionBlock blocoAcaoFalseObj = new ActionBlock(blocoAcaoFalse);

            Decision decisao = new Decision(inequacao, blocoAcaoTrueObj, blocoAcaoFalseObj);
            maquinaInequacoes.DecisionsList.AddDecision(decisao);

            maquinaInequacoes.Compile();

            maquinaInequacoes.Execute();

            Assert.AreEqual(maquinaInequacoes.CalculationMemory["a"].GetValue(), a);
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["b"].GetValue(), b);
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);

            expressao = "(a >= b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);

            expressao = "(a<b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            expressao = "(a <= b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            expressao = "(a = b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            horaA = "15:17:31";
            horaB = "15:27:31";
            if (!DateTime.TryParseExact(horaA, pattern, null, System.Globalization.DateTimeStyles.None, out a) || !DateTime.TryParseExact(horaB, pattern, null, System.Globalization.DateTimeStyles.None, out b))
            {
                throw new Exception("Erro no parsing das variáveis de hora.");
            }
            maquinaInequacoes.CalculationMemory.UpdateVariable("a", a);
            maquinaInequacoes.CalculationMemory.UpdateVariable("b", b);

            expressao = "(a > b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            expressao = "(a < b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);

            expressao = "(a >= b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            expressao = "(a <= b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);

            expressao = "(a = b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            horaA = "11:00:22";
            horaB = "11:00:22";
            if (!DateTime.TryParseExact(horaA, pattern, null, System.Globalization.DateTimeStyles.None, out a) || !DateTime.TryParseExact(horaB, pattern, null, System.Globalization.DateTimeStyles.None, out b))
            {
                throw new Exception("Erro no parsing das variáveis de hora.");
            }
            maquinaInequacoes.CalculationMemory.UpdateVariable("a", a);
            maquinaInequacoes.CalculationMemory.UpdateVariable("b", b);

            expressao = "(a > b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            expressao = "(a < b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 0.0);

            expressao = "(a >= b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);

            expressao = "(a <= b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);

            expressao = "(a = b)";
            decisao.Inequation.Expression = expressao;
            maquinaInequacoes.Compile();
            maquinaInequacoes.Execute();
            Assert.AreEqual(maquinaInequacoes.CalculationMemory["result"].GetValue(), 100.0);
        }
Ejemplo n.º 4
0
 public Decision(Inequation inequation, ActionBlock trueActionBlock, ActionBlock falseActionBlock)
 {
     _inequation = inequation;
     _trueActionBlock = trueActionBlock;
     _falseActionBlock = falseActionBlock;
 }