Exemplo n.º 1
0
        public void TestOperators()
        {
            CParser testparser = new CParser();

            String[] ExpressionsUse = {"12+5","{1,2,3}","14-12+5*Sqr(64)"};
            Object[] Expectedresults = {(object)17,(object)(new object[] {1f,2f,3f}).ToList(),14-12+5*8};
            int failcount=0;

            for (int i = 0; i < ExpressionsUse.Length; i++)
            {

                Object tempobject = testparser.Execute(ExpressionsUse[i]);
                if (Convert.ChangeType(tempobject, Expectedresults[i].GetType()).Equals( Expectedresults[i])
                    || (testparser.ResultToString(tempobject).Equals(testparser.ResultToString(Expectedresults[i])))
                    )
                //if (tempobject == Expectedresults[i])
                {
                    Debug.Print(ExpressionsUse[i] + " success. Result was " + testparser.ResultToString(tempobject));

                }
                else
                {
                    Debug.Print(ExpressionsUse[i] + " failed. Result was " + testparser.ResultToString(tempobject) + "Expected result was " + testparser.ResultToString(Expectedresults[i]));

                    failcount++;

                }

            }
            if (failcount > 0)
                Assert.Fail(failcount.ToString() + "/" + ExpressionsUse.Length + " tests failed.");
        }
Exemplo n.º 2
0
        public void TestOperators()
        {
            CParser testparser = new CParser();

            String[] ExpressionsUse  = { "12+5", "{1,2,3}", "14-12+5*Sqr(64)" };
            Object[] Expectedresults = { (object)17, (object)(new object[] { 1f, 2f, 3f }).ToList(), 14 - 12 + 5 * 8 };
            int      failcount       = 0;

            for (int i = 0; i < ExpressionsUse.Length; i++)
            {
                Object tempobject = testparser.Execute(ExpressionsUse[i]);
                if (Convert.ChangeType(tempobject, Expectedresults[i].GetType()).Equals(Expectedresults[i]) ||
                    (testparser.ResultToString(tempobject).Equals(testparser.ResultToString(Expectedresults[i])))
                    )
                //if (tempobject == Expectedresults[i])
                {
                    Debug.Print(ExpressionsUse[i] + " success. Result was " + testparser.ResultToString(tempobject));
                }
                else
                {
                    Debug.Print(ExpressionsUse[i] + " failed. Result was " + testparser.ResultToString(tempobject) + "Expected result was " + testparser.ResultToString(Expectedresults[i]));

                    failcount++;
                }
            }
            if (failcount > 0)
            {
                Assert.Fail(failcount.ToString() + "/" + ExpressionsUse.Length + " tests failed.");
            }
        }
Exemplo n.º 3
0
        private void btnexec_Click(object sender, EventArgs e)
        {
            mParser.Expression = txtinput.Text;
            Object resultacquired = null;

            try
            {
                resultacquired = mParser.Execute();
                String stringresult = mParser.ResultToString(resultacquired);
                txtresults.Text += System.Environment.NewLine + stringresult;
            }
            catch (Exception err)
            {
                txtresults.Text += System.Environment.NewLine;
                txtresults.Select(txtresults.Text.Length, 0);
                txtresults.SelectedText = "Exception:" + err.Message + " Source: " + err.Source + System.Environment.NewLine +
                                          "Stack trace:" + System.Environment.NewLine + err.StackTrace + System.Environment.NewLine;
                txtresults.SelectionFont = new Font(txtresults.SelectionFont, FontStyle.Bold);
                txtresults.Select(txtresults.Text.Length, 0);
                txtresults.ScrollToCaret();
            }
        }