public void FindsExitOrQuitInInput()
 {
     string input = "exit";
     var calc = new Calculate(input);
     calc.inputIsntGoingToBeCalculated(input);
     Assert.AreEqual(Calculate.response, "goodbye, fool");
 }
예제 #2
0
        public void MultipleVariablesCanBeUnsetAtTheSameTime()
        {
            var count = Variable.Variables.Count;
            var unsetVariable = new UnsetVariable();
            var calculate = new Calculate();

            Assert.AreEqual("x = 2", _inputHandler.HandleInput("set x = 2"));
            Assert.AreEqual("y = 4", _inputHandler.HandleInput("set y = 4"));
            Assert.AreEqual("z = 6", _inputHandler.HandleInput("set z = 6"));
            Assert.AreEqual(count + 3, Variable.Variables.Count);

            Assert.AreEqual("Variable x unset.", _inputHandler.HandleInput("unset x"));
            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset x"));
            Assert.AreEqual(count + 2, Variable.Variables.Count);

            Assert.AreEqual("Variables z, y unset.", _inputHandler.HandleInput("unset z,    y"));
            Assert.AreEqual(count, Variable.Variables.Count);

            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset y, z"));
            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset z"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("x"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("y"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("z"));

            Assert.AreEqual("y = 4", _inputHandler.HandleInput("set y = 4"));
            Assert.AreEqual("z = 6", _inputHandler.HandleInput("set z = 6"));
            Assert.AreEqual("Variables y, z unset.", _inputHandler.HandleInput("unset y;  z"));
        }
 public void CalculateResponseReturnsStringResponse()
 {
     string input = "4+7";
     var calc = new Calculate(input);
     var response = calc.CalculateResponse(new int[] { 1, 7 }, '+');
     Assert.AreEqual(response, "8");
 }
예제 #4
0
 private void btnCompute_Click(object sender, EventArgs e)
 {
     String expression = tbInput.Text;
     Calculate cal = new Calculate(expression);
     double output = cal.output();
     tbOutput.Text = output.ToString();
 }
 public void lastLastqAndExitQuitDoNotNeedToBeCalculated()
 {
     string input = "lastq";
     Stack.lastResponse = "5*13";
     var calc = new Calculate(input);
     bool isGonna = calc.inputIsntGoingToBeCalculated(input);
     Assert.AreEqual(true, isGonna);
 }
 public void FindsLastInInput()
 {
     string input = "last";
     Stack.lastResponse = "65";
     var calc = new Calculate(input);
     calc.inputIsntGoingToBeCalculated(input);
     Assert.AreEqual(Calculate.response, Stack.lastResponse);
 }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InputHandler"/> class.
 /// </summary>
 public InputHandler()
 {
     _fraction = new Fraction();
     _setVariable = new SetVariable();
     _unsetVariable = new UnsetVariable();
     _variables = new Variables();
     _calculate = new Calculate();
     _help = new Help();
 }
예제 #8
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Kate-tastic Calculator. Begin.");
            bool keepGoing = true;
            while (keepGoing)
            {
                Console.Write(String.Format("[{0}]>", Calculate.Counter));
                var input = Regex.Replace(Console.ReadLine().ToLower(), @"\s+", "");
                var c = new Calculate(input);
                if (Calculate.response == "goodbye, fool")
                {
                    keepGoing = false;
                }
                Console.WriteLine(Calculate.response);

            }
        }
예제 #9
0
        /// <summary>
        /// Handles the input.
        /// </summary>
        /// <param name="initialInput">The initial input.</param>
        /// <returns></returns>
        public override string HandleInput(string initialInput)
        {
            var calculate = new Calculate();
            var index = 0;

            if ( StringParse.StringStartsWith(initialInput, Command) )
            {
                index = Command.Length;
            }

            try
            {
                calculate.HandleInput(initialInput.Substring(index));
            }
            catch (CalculatorException e)
            {
                e.ErrorIndex += index;
                throw e;
            }
            return Calculate.DoubleToFraction(Variable.ANS.Value);
        }
예제 #10
0
        private void button15_Click(object sender, EventArgs e)                  //验证平行轴定理
        {
            Cal[11] = Convert.ToDouble(Calculate.ExcelToString(path, 1, 25, 2)); //下圆盘直径

            Cal[12] = Convert.ToDouble(Calculate.ExcelToString(path, 1, 26, 2)); //下圆盘质量

            Cal[13] = Convert.ToDouble(Calculate.ExcelToString(path, 1, 27, 2)); //圆柱体质量

            //计算转动惯量理论值
            Calculate.ExcelToString(path, 1, 22, 2, false);

            Calculate.StringToDouble(temp);

            Calculate.Itheory(Cal[13], Cal[15], Convert1);

            //计算转动惯量实验值
            Calculate.ExcelToString(path, 1, 23, 2, false);

            Calculate.StringToDouble(temp);

            Calculate.Ireality(Cal, Convert1);

            //计算百分误差
            Calculate.Ibaifenwucha(iTheoryOutput, iRealityOutput);

            //激活对应按钮控件
            button9.Enabled = true;

            button10.Enabled = true;

            button11.Enabled = true;

            button12.Enabled = true;

            button13.Enabled = true;

            button14.Enabled = true;
        }
예제 #11
0
        public void VariablesCanBeUnset()
        {
            var count = Variable.Variables.Count;

            Assert.AreEqual("x = 2", _inputHandler.HandleInput("set x = 2"));
            Assert.AreEqual(count + 1, Variable.Variables.Count);

            Assert.AreEqual("Variable x unset.", _inputHandler.HandleInput("unset x"));
            Assert.AreEqual(count, Variable.Variables.Count);

            var unsetVariable = new UnsetVariable();
            var calculate = new Calculate();

            Assert.Throws<CalculatorException>(() => unsetVariable.HandleInput("unset x"));
            Assert.Throws<CalculatorException>(() => calculate.HandleInput("x"));
        }
예제 #12
0
파일: Form3.cs 프로젝트: DGPLM/Calculator
        private void button1_Click_1(object sender, EventArgs e)
        {
            System.Windows.Forms.TextBox[] tb1 = new System.Windows.Forms.TextBox[48];

            tb1[0] = textBox1;

            tb1[1] = textBox2;

            tb1[2] = textBox3;

            tb1[3] = textBox4;

            tb1[4] = textBox5;

            tb1[5] = textBox6;

            tb1[6] = textBox7;

            tb1[7] = textBox8;

            tb1[8] = textBox9;

            tb1[9] = textBox10;

            tb1[10] = textBox11;

            tb1[11] = textBox12;

            tb1[12] = textBox13;

            tb1[13] = textBox14;

            tb1[14] = textBox15;

            tb1[15] = textBox16;

            tb1[16] = textBox17;

            tb1[17] = textBox18;

            tb1[18] = textBox19;

            tb1[19] = textBox20;

            tb1[20] = textBox21;

            tb1[21] = textBox22;

            tb1[22] = textBox23;

            tb1[23] = textBox24;

            tb1[24] = textBox25;

            tb1[25] = textBox26;

            tb1[26] = textBox27;

            tb1[27] = textBox28;

            tb1[28] = textBox29;

            tb1[29] = textBox30;

            tb1[30] = textBox31;

            tb1[31] = textBox32;

            tb1[32] = textBox33;

            tb1[33] = textBox34;

            tb1[34] = textBox35;

            tb1[35] = textBox36;

            tb1[36] = textBox37;

            tb1[37] = textBox38;

            tb1[38] = textBox39;

            tb1[39] = textBox40;

            tb1[40] = textBox41;

            tb1[41] = textBox42;

            tb1[42] = textBox43;

            tb1[43] = textBox44;

            tb1[44] = textBox45;

            tb1[45] = textBox46;

            tb1[46] = textBox47;

            tb1[47] = textBox48;

            for (int i = 0; i < tb1.Length; i++)
            {
                if (tb1[i].Text == "")
                {
                    MessageBox.Show("数据缺少,请输入!");

                    tb1[i].Focus();

                    return;

                    if (tb1[i].Text != "")
                    {
                        continue;
                    }
                }
            }

            string a = tb1[45].Text;//创建abc三个变量存储路径名,以便后面更改

            string b = tb1[46].Text;

            string c = tb1[47].Text;

            if (a == "")
            {
                MessageBox.Show("班级名不能为空,请输入!");

                tb1[45].Focus();
            }

            if (a != "" && c == "")
            {
                MessageBox.Show("姓名不能为空,请输入!");

                tb1[47].Focus();
            }

            if (a != "" && b == "")
            {
                MessageBox.Show("学号不能为空,请输入!");

                tb1[46].Focus();
            }

            if (a != "" && b != "" && c != "")//当abc三个变量都存在时,生成数据文件
            {
                Calculate.InputData(tb1, a, b, c);
            }

            for (int i = 0; i < tb1.Length; i++)
            {
                tb1[i].Clear();
            }
        }
예제 #13
0
 private void Run_Click(object sender, EventArgs e)
 {
     Log.Text = Calculate.Calc(textin.Text);
 }
예제 #14
0
파일: Program.cs 프로젝트: yesuf/cal1
        public static void sliceEquation(string inputValue)
        {
            if (inputValue == "done")
                Environment.Exit(0);
            string firstNumber = "", secondNumber = "", equationOperator = "";
            ushort n = 1, end = 0;

            while (Regex.IsMatch(inputValue.Substring(0, n), @"^\d+$"))
            {
                firstNumber = inputValue.Substring(0, n);
                if (!(Regex.IsMatch(inputValue[n].ToString(), @"^\d+$")))
                {
                    equationOperator = inputValue[n].ToString();
                    break;
                }
                if (n > inputValue.Length)
                    break;
                n++;
            }
            end = (ushort)(inputValue.Length - (firstNumber.Length + 1));
            secondNumber = inputValue.Substring((n + 1), end);
            Calculate p = new Calculate(ulong.Parse(firstNumber), ulong.Parse(secondNumber), equationOperator);
        }
예제 #15
0
 private void Input_line_TextChanged(object sender, TextChangedEventArgs e)
 {
     Answer_line.Text = Calculate.compute(Input_line.Text);
 }
예제 #16
0
 public static Decimal calculate(String data)
 {
     return(Calculate.getInstance().start(data));
 }
예제 #17
0
        //If the equals button has been pressed the result is cleared and handles reset.
        //If not, the last digit or operator is deleted from the input. Checks are done to ensure
        //that multiple operators, decimal points etc can't be entered afterwards.
        //If the input is completely deleted then everything is cleared.
        private void Delete()
        {
            if (resulted == true)
            {
                lblDisplay1.Text = "";
                lblDisplay3.Text = "";
                workingString    = "";
                result           = 0;
                decimalPointed   = false;
                newNumber        = true;
            }
            else
            {
                if (workingString.Length > 0)
                {
                    workingString = workingString.Remove(workingString.Length - 1);

                    if (workingString.Length > 0 && Calculate.CheckContainsOperators(workingString) &&
                        !Calculate.CheckForDoubleOperator(workingString))
                    {
                        result           = Calculate.calculate(workingString);
                        lblDisplay3.Text = result.ToString();
                    }

                    if (workingString.Contains("."))
                    {
                        if (Calculate.CheckContainsOperators(workingString))
                        {
                            string[] splitString;
                            splitString = workingString.Split('+', '-', '*', '/');

                            if (splitString[splitString.Length - 1].Contains("."))
                            {
                                decimalPointed = true;
                            }
                            else
                            {
                                decimalPointed = false;
                            }
                        }
                        else
                        {
                            decimalPointed = true;
                        }
                    }
                    else
                    {
                        decimalPointed = false;
                    }

                    if (Calculate.CheckContainsOperators(workingString))
                    {
                        string[] splitString;
                        splitString = workingString.Split('+', '-', '*', '/');

                        if (splitString[splitString.Length - 1].Length == 0)
                        {
                            newNumber = true;
                        }
                    }

                    lblDisplay1.Text = "";
                    Display();
                }
                else
                {
                    lblDisplay1.Text = "";
                    lblDisplay3.Text = "";
                    workingString    = "";
                    result           = 0;
                    decimalPointed   = false;
                    newNumber        = true;
                }
            }
        }
예제 #18
0
 public Operator(Calculate calc, int count)
 {
     this.calc         = calc;
     this.varibleCount = count;
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetVariable"/> class.
 /// </summary>
 public SetVariable()
 {
     _calculate = new Calculate();
 }
예제 #20
0
파일: Form1.cs 프로젝트: cddchen/homework
        private void OnClick(object sender, EventArgs e)
        {
            string name = (sender as UserControl).Name;

            switch (name)
            {
            case "MemoryClear":
                cal.MemoryClear();
                break;

            case "MemoryAdd":
                if (Calculate.checkInput(Ans.Text))
                {
                    cal.MemoryAdd(Ans.Text);
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;

            case "MemorySub":
                if (Calculate.checkInput(Ans.Text))
                {
                    cal.MemorySub(Ans.Text);
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                cal.MemorySub(Ans.Text);
                break;

            case "MemoryRead":
                Ans.Text = cal.MemoryRead();
                break;

            case "num0":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "0";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "0";
                    }
                    else
                    {
                        Ans.Text += "0";
                    }
                }
                break;

            case "num1":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "1";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "1";
                    }
                    else
                    {
                        Ans.Text += "1";
                    }
                }
                break;

            case "num2":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "2";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "2";
                    }
                    else
                    {
                        Ans.Text += "2";
                    }
                }
                break;

            case "num3":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "3";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "3";
                    }
                    else
                    {
                        Ans.Text += "3";
                    }
                }
                break;

            case "num4":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "4";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "4";
                    }
                    else
                    {
                        Ans.Text += "4";
                    }
                }
                break;

            case "num5":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "5";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "5";
                    }
                    else
                    {
                        Ans.Text += "5";
                    }
                }
                break;

            case "num6":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "6";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "6";
                    }
                    else
                    {
                        Ans.Text += "6";
                    }
                }
                break;

            case "num7":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "7";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "7";
                    }
                    else
                    {
                        Ans.Text += "7";
                    }
                }
                break;

            case "num8":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "8";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "8";
                    }
                    else
                    {
                        Ans.Text += "8";
                    }
                }
                break;

            case "num9":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "9";
                    isDisplayTemAns = false;
                }
                else
                {
                    if (Ans.Text == "0")
                    {
                        Ans.Text = "9";
                    }
                    else
                    {
                        Ans.Text += "9";
                    }
                }
                break;

            case "numPoint":
                if (isDisplayTemAns)
                {
                    Ans.Text        = "0.";
                    isDisplayTemAns = false;
                }
                else
                {
                    Ans.Text += ".";
                }
                break;

            case "AllClear":
                cal.AllClear();
                Ans.Text = "0";
                break;

            case "PosOrNeg":
                if (Calculate.checkInput(Ans.Text))
                {
                    Ans.Text = cal.PosOrNeg();
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;

            case "Div":
                if (Calculate.checkInput(Ans.Text))
                {
                    Ans.Text        = cal.Cal(op, Ans.Text);
                    op              = Operation.Div;
                    isDisplayTemAns = true;
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;

            case "Mul":
                if (Calculate.checkInput(Ans.Text))
                {
                    Ans.Text        = cal.Cal(op, Ans.Text);
                    op              = Operation.Mul;
                    isDisplayTemAns = true;
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;

            case "Add":
                if (Calculate.checkInput(Ans.Text))
                {
                    Ans.Text        = cal.Cal(op, Ans.Text);
                    op              = Operation.Add;
                    isDisplayTemAns = true;
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;

            case "Sub":
                if (Calculate.checkInput(Ans.Text))
                {
                    Ans.Text        = cal.Cal(op, Ans.Text);
                    op              = Operation.Sub;
                    isDisplayTemAns = true;
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;

            case "Equal":
                if (Calculate.checkInput(Ans.Text))
                {
                    Ans.Text        = cal.Cal(op, Ans.Text);
                    op              = Operation.Null;
                    isDisplayTemAns = true;
                }
                else
                {
                    MessageBox.Show("输入不合法");
                }
                break;
            }
        }
예제 #21
0
 protected void Page_Load(object sender, EventArgs e)
 {
     _Calculate = new Calculate();
 }
예제 #22
0
 protected void SetUp()
 {
     _calculate = new Calculate();
 }