Exemplo n.º 1
0
        public void TestMethod1()
        {
            string  x        = "34+2/(3*4-12)";
            string  expected = "#ERROR";
            Parser2 pasre    = new Parser2();
            Result  res      = pasre.Evaluate(x);
            string  actual   = res.GetValue();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        public void TestMethod4()
        {
            string  x        = "min(56+5/4div2,)";
            string  expected = "#ERROR";
            Parser2 pasre    = new Parser2();
            Result  res      = pasre.Evaluate(x);
            string  actual   = res.GetValue();

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void TestMethod1()
        {
            string  x        = "12+(2*3)-3";
            double  expected = 15;
            Parser2 parse    = new Parser2();
            Result  res      = parse.Evaluate(x);
            double  actual   = res.Value;

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 4
0
        public void TestMethod()
        {
            string  x        = "(48-3)mod(56-3)*4";
            double  expected = 180;
            Parser2 pasre    = new Parser2();
            Result  res      = pasre.Evaluate(x);
            double  actual   = res.Value;

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 5
0
        public void TestMethod4()
        {
            string  x        = "min(38+6/3*4+20,max(48-3*0,56-3*4))";
            double  expected = 48;
            Parser2 pasre    = new Parser2();
            Result  res      = pasre.Evaluate(x);
            double  actual   = res.Value;

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 6
0
        public void TestMethod2()
        {
            string  x        = "(12mod3/3)*2div3";
            double  expected = 0;
            Parser2 pasre    = new Parser2();
            Result  res      = pasre.Evaluate(x);
            double  actual   = res.Value;

            Assert.AreEqual(actual, expected);
        }
Exemplo n.º 7
0
        public void AddNewVal(string exp, int row, int column, Cell[,] table, DataGridView Table)
        {//replace Cell Name with value
            table[row, column].exp = exp;
            index = 0;
            if (exp != null)
            {
                while (index < exp.Length)
                {
                    string str = null;
                    int    t2, t1 = (int)exp[index];
                    str += exp[index];
                    index++;
                    if (t1 > 64 && t1 < 91 && index < exp.Length)
                    {
                        str += exp[index];
                        t2   = (int)exp[index] - 48;
                        index++;
                        if (index < exp.Length && exp[index] != ' ' && "+-/*<>=".IndexOf(exp[index]) != -1)
                        {
                            str += exp[index];
                            t2  *= 10;
                            t2  += (int)exp[index] - 48;
                        }
                        table[t2, t1 - 65].dependend.Add(table[row, column]);
                        exp = exp.Replace(str, table[t2, t1 - 65].value);
                        MessageBox.Show(exp);
                    }
                }
            }
            Result result = parser2.Evaluate(exp);

            if (result.Except())
            {
                table[row, column].value            = result.GetValue();
                Table.Rows[row].Cells[column].Value = result.GetValue();
                //UpdateForm(row, column, table, Table);
            }
            Table.Rows[row].Cells[column].Value = result.GetValue();
            //MessageBox.Show("У підрахунках виникла помилка, перевірте будь ласка правильність формули");
        }
Exemplo n.º 8
0
        public void AddNewValue(string expression, int r, int c, bool k)
        {
            int    Count = 0;
            Result result1;

            table[r, c].exp = expression;

            int h = 0;

            // expression.Replace(" ","");
            //MessageBox.Show(expression);
            if (expression != null)
            {
                while (h < expression.Length)
                {
                    string str = null;
                    int    t2, t1 = (int)expression[h];
                    str += expression[h];
                    h++;

                    if (t1 > 64 && t1 < 91 && h < expression.Length)
                    {
                        str += expression[h];
                        t2   = (int)expression[h] - 48;
                        h++;
                        if (h < expression.Length && expression[h] != ' ' && expression[h] > 47 && expression[h] < 58)
                        {
                            str += expression[h];
                            t2  *= 10;
                            t2  += (int)expression[h] - 48;
                        }
                        if (k == true)
                        {
                            table[t2, t1 - 65].depends.Add(table[r, c].getName(c, r));

                            table[r, c].dependend.Add(table[t2, t1 - 65]);
                        }
                        if (circle(table[r, c], r, c, r, c) == false)
                        {
                            table[t2, t1 - 65].depends.RemoveAt(table[t2, t1 - 65].depends.Count - 1);
                            MessageBox.Show("Неможливо застосувати формулу, клітинка вказує сама на себе");
                            Table.Rows[Table.CurrentCell.RowIndex].Cells[Table.CurrentCell.ColumnIndex].Value = "";
                            table[r, c].value = "0";
                            table[r, c].exp   = null;
                            AddNewValue(table[r, c].exp, r, c, true);
                            break;
                        }
                        expression = expression.Replace(str, table[t2, t1 - 65].value);
                        Count++;
                    }
                }
            }
            if (circle(table[r, c], r, c, r, c) == true)
            {
                if (expression.Contains(">") || expression.Contains("<") || expression.Contains("="))
                {
                    result1 = parser2.Evaluate0(expression);
                }
                else
                {
                    result1 = parser2.Evaluate(expression);
                }
                if (result1.Except())
                {
                    table[r, c].value = result1.GetValue();
                    // MessageBox.Show(table[r, c].value);


                    Table.Rows[r].Cells[c].Value = result1.GetValue();    ///////////
                    update(table[r, c], r, c);
                }
                else
                {
                    Table.Rows[r].Cells[c].Value = result1.GetValue();
                }
            }
            else
            {
                MessageBox.Show("Неможливо застосувати формулу, клітинка вказує сама на себе");
                Table.Rows[Table.CurrentCell.RowIndex].Cells[Table.CurrentCell.ColumnIndex].Value = "";
            }
        }