Esempio n. 1
0
        public void Caculate_Test()
        {
            Arithmetic arithmetic   = new Arithmetic();
            string     testData     = "9+(3-1)*3+10/2";
            int        expectedData = 20;
            int        actualData   = arithmetic.Calculate(testData);

            _testOutputHelper.WriteLine(testData);
            _testOutputHelper.WriteLine(actualData.ToString());
            Assert.Equal(expectedData, actualData);

            testData     = "9/(3-2*1)*3+10/2";
            expectedData = 32;
            actualData   = arithmetic.Calculate(testData);

            _testOutputHelper.WriteLine("");
            _testOutputHelper.WriteLine(testData);
            _testOutputHelper.WriteLine(actualData.ToString());
            Assert.Equal(expectedData, actualData);
        }
Esempio n. 2
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                string       input = textBox1.Text;
                List <Token> rpn   = Arithmetic.Calculate(input);
                if (rpn != null)
                {
                    Dictionary <string, bool> variables = Arithmetic.GetVariables(rpn);
                    var manager = new BDDManager(variables.Count);
                    var root    = Arithmetic.CreateTree(rpn, variables, manager);
                    if (root != null)
                    {
                        List <BDDNode> list = root.Nodes.ToList();

                        var v1 = new Dictionary <int, string>();
                        int j  = 0;
                        foreach (KeyValuePair <string, bool> kv in variables)
                        {
                            v1.Add(j, kv.Key);
                            j++;
                        }
                        manager.Reduce(root);
                        Func <BDDNode, string> labelFunction = (x) => v1[x.Index];
                        Bitmap bm = new Bitmap(Graphviz.RenderImage(manager.ToDot(root, labelFunction, false), "jpg"));
                        pictureBox1.Image = bm;
                        label1.Text       = "Готово";
                    }
                    else
                    {
                        label1.Text = "Ошибка при вычислении логической формулы";
                    }
                }
                else
                {
                    label1.Text = "Ошибка ввода логической формулы";
                }
            }
        }