コード例 #1
0
        /// <summary>
        /// When user clicks on the button "="
        /// </summary>
        /// <param name="sender">System.Windows.Forms.Button</param>
        /// <param name="e">System.Windows.Forms.MouseEventArgs</param>
        private void EqualBtn_Click(object sender, EventArgs e)
        {
            try
            {
                string toCalculate = AnalyseUtils.AnalyseAndReplace(ComputeTextBox.Text);
                ComputeTextBox.Text = ComputeUtils.DoTheMath(toCalculate);

                bool isGoodPassword = connection.CheckIfLoginPagePassword(toCalculate);

                if (isGoodPassword)
                {
                    Hide();
                    LoginForm loginForm = new LoginForm();
                    loginForm.Show();
                }
            }
            catch (SyntaxErrorException)
            {
                MessageBox.Show("Erreur de syntaxe.", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        public void DoTheMathAndMultDouble()
        {
            string result = ComputeUtils.DoTheMath("1.5 * 10 + 2.5 * 10");

            Assert.AreEqual(double.Parse(result), 40);
        }
コード例 #3
0
        public void DoTheMathAndDivideDouble()
        {
            string result = ComputeUtils.DoTheMath("1 / 10 + 1 / 10");

            Assert.AreEqual(double.Parse(result), 0.20);
        }
コード例 #4
0
        public void DoTheMathAndSquare()
        {
            string result = ComputeUtils.DoTheMath("5 * 5 + 3");

            Assert.AreEqual(int.Parse(result), 28);
        }
コード例 #5
0
        public void DoTheMathAndDivide()
        {
            string result = ComputeUtils.DoTheMath("5 / 5 * 2 + 3 - 2");

            Assert.AreEqual(int.Parse(result), 3);
        }
コード例 #6
0
        public void DoTheMathWithoutParentheses()
        {
            string result = ComputeUtils.DoTheMath("5 + 8 * 2 + 3 - 2");

            Assert.AreEqual(int.Parse(result), 22);
        }
コード例 #7
0
        public void DoTheMathTestWithParentheses()
        {
            string result = ComputeUtils.DoTheMath("( 5 + 8 ) * 2 + 3 - 2");

            Assert.AreEqual(int.Parse(result), 27);
        }