public void HandleButtonPlusTest()
 {
     _calculatorHelper = new CalculatorHelper();
     _calculatorHelper.HandleButton1();
     _calculatorHelper.HandleButtonPlus();
     Assert.AreEqual("1 +", CalculatorHelper.DisplayText);
 }
Beispiel #2
0
 public static CalculatorHelper GetInstance()
 {
     if (_instance == null)
     {
         _instance = new CalculatorHelper();
     }
     return(_instance);
 }
        public void StateIsEnteringOperand2Test()
        {
            _calculatorHelper = new CalculatorHelper();

            // 1 + 1
            _calculatorHelper.HandleButton1();
            _calculatorHelper.HandleButtonPlus();
            _calculatorHelper.HandleButton1();
            Assert.AreEqual(CalculatorStates.EnteringOperand2, CalculatorHelper.State);
        }
        public void DisplayShowsOnePlusOneTest()
        {
            _calculatorHelper = new CalculatorHelper();

            // 1 + 1
            _calculatorHelper.HandleButton1();
            _calculatorHelper.HandleButtonPlus();
            _calculatorHelper.HandleButton1();
            Assert.AreEqual("1 + 1", CalculatorHelper.DisplayText);
            Assert.AreEqual(1, CalculatorHelper.Operand2);
        }
 private void GiveResult(object sender, RoutedEventArgs e)
 {
     try
     {
         resultLabel.Content = CalculatorHelper.CalCulateGlobalResult(resultLabel.Content.ToString());
     }
     catch
     {
         resultLabel.Content = CalculatorHelper.errorSyntax;
     }
 }
Beispiel #6
0
        private void OperatorButton_Click(object sender, RoutedEventArgs e)
        {
            if (!(sender is Button button))
            {
                return;
            }

            char     c  = ((string)button.Content)[0];
            Operator op = CalculatorHelper.CharToOperator(c);

            _calculator.SetOperator(op);
        }
Beispiel #7
0
        public static void Slove(string x, string y, string operation)
        {
            double a;
            double b;

            if (CalculatorHelper.CheckNumCondition(x) && CalculatorHelper.CheckNumCondition(y))
            {
                double.TryParse(x, out a);
                double.TryParse(y, out b);

                switch (operation)
                {
                case "M":
                    Console.WriteLine(a * b);
                    break;

                case "D":
                    Console.WriteLine(a / b);
                    break;

                case "A":
                    Console.WriteLine(a - b);
                    break;

                case "S":
                    Console.WriteLine(a + b);
                    break;

                default:
                    Console.WriteLine("error");
                    break;
                }
            }
            else
            {
                Console.WriteLine("error");
            }
        }
 public void StateIsClearAtStartUpTest()
 {
     _calculatorHelper = new CalculatorHelper();
     Assert.AreEqual(CalculatorStates.Clear, CalculatorHelper.State);
 }
 public void HandleButton1Test()
 {
     _calculatorHelper = new CalculatorHelper();
     _calculatorHelper.HandleButton1();
     Assert.AreEqual(1, CalculatorHelper.Operand1);
 }
 public void DisplayShows1Test()
 {
     _calculatorHelper = new CalculatorHelper();
     _calculatorHelper.HandleButton1();
     Assert.AreEqual("1", CalculatorHelper.DisplayText);
 }
 public CalculatorForm()
 {
     InitializeComponent();
     CalculatorHelper = new CalculatorHelper();
 }