public void CalculatorViewModel_InValidOperationTest()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            //try -7 + 42 = 35
            vm.DigitButtonPress("7");
            vm.DigitButtonPress("+/-");

            vm.OperationButtonPress("@");
            vm.DigitButtonPress("4");
            vm.DigitButtonPress("2");

            Assert.AreEqual(vm.FirstOperand, "-7");
            Assert.AreEqual(vm.Display, "42");

            try
            {
                //perform operation
                vm.OperationButtonPress("=");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(ArgumentException));
            }

            Assert.AreEqual(vm.Operation, "@");
            Assert.AreEqual(vm.SecondOperand, "42");

            Assert.AreEqual(vm.Display, "Unknown operation: @");
        }
        public void CalculatorViewModel_ValidOperationTestThenClear()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            //try -7 + 42 = 35
            vm.DigitButtonPress("7");
            vm.DigitButtonPress("+/-");

            vm.OperationButtonPress("+");
            vm.DigitButtonPress("4");
            vm.DigitButtonPress("2");

            Assert.AreEqual(vm.FirstOperand, "-7");
            Assert.AreEqual(vm.Display, "42");

            //perform operation
            vm.OperationButtonPress("=");

            Assert.AreEqual(vm.Operation, "+");
            Assert.AreEqual(vm.SecondOperand, "42");

            Assert.AreEqual(vm.Display, "35");
            Assert.AreEqual(vm.FullExpression, "-7 + 42 = 35");

            //ClearAll
            vm.DigitButtonPress("C");

            Assert.AreEqual(vm.Display, "0");
            Assert.AreEqual(vm.FirstOperand, string.Empty);
            Assert.AreEqual(vm.SecondOperand, string.Empty);
            Assert.AreEqual(vm.Operation, string.Empty);
            Assert.AreEqual(vm.LastOperation, string.Empty);
            Assert.AreEqual(vm.FullExpression, string.Empty);
        }
Exemplo n.º 3
0
 private void ClearButton_Click(object sender, RoutedEventArgs e)
 {
     ViewModels.CalculatorViewModel _viewModel = (this.DataContext as ViewModels.CalculatorViewModel);
     if (_viewModel.ClearCommand.CanExecute(null))
     {
         _viewModel.ClearCommand.Execute(null);
     }
 }
        public void CalculatorViewModel_ConstructorTest()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            Assert.IsTrue(vm.GetType() == typeof(ViewModels.CalculatorViewModel));
            Assert.AreEqual(vm.Display, "0");
            Assert.AreEqual(vm.FirstOperand, string.Empty);
            Assert.AreEqual(vm.SecondOperand, string.Empty);
            Assert.AreEqual(vm.Operation, string.Empty);
            Assert.AreEqual(vm.LastOperation, string.Empty);
            Assert.AreEqual(vm.FullExpression, string.Empty);
        }
        public void CalculatorViewModel_CompositeOperationTestThenClear()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            //try -7 + 42 = 35
            vm.DigitButtonPress("7");
            vm.DigitButtonPress("+/-");

            vm.OperationButtonPress("+");
            vm.DigitButtonPress("4");
            vm.DigitButtonPress("2");

            Assert.AreEqual(vm.FirstOperand, "-7");
            Assert.AreEqual(vm.Display, "42");

            //perform operation
            vm.OperationButtonPress("+");

            Assert.AreEqual(vm.Operation, "+");
            Assert.AreEqual(vm.SecondOperand, "42");

            Assert.AreEqual(vm.Display, "35");
            Assert.AreEqual(vm.FullExpression, "-7 + 42 = 35");

            vm.DigitButtonPress("1");
            vm.DigitButtonPress("0");

            //perform operation
            vm.OperationButtonPress("=");

            Assert.AreEqual(vm.Display, "45");
            Assert.AreEqual(vm.FullExpression, "35 + 10 = 45");

            //perform tan(45)
            vm.SingularOperationButtonPress("tan");

            Assert.AreEqual(vm.Display, "1");
            Assert.AreEqual(vm.FullExpression, "tan(45) = 1");
        }
        public void CalculatorViewModel_CompositeOperationTestThenClear()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            //try -7 + 42 = 35
            vm.DigitButtonPress("7");
            vm.DigitButtonPress("+/-");

            vm.OperationButtonPress("+");
            vm.DigitButtonPress("4");
            vm.DigitButtonPress("2");

            Assert.AreEqual(vm.FirstOperand, "-7");
            Assert.AreEqual(vm.Display, "42");

            //perform operation
            vm.OperationButtonPress("+");

            Assert.AreEqual(vm.Operation, "+");
            Assert.AreEqual(vm.SecondOperand, "42");

            Assert.AreEqual(vm.Display, "35");
            Assert.AreEqual(vm.FullExpression, "-7 + 42 = 35");

            vm.DigitButtonPress("1");
            vm.DigitButtonPress("0");

            //perform operation
            vm.OperationButtonPress("=");

            Assert.AreEqual(vm.Display, "45");
            Assert.AreEqual(vm.FullExpression, "35 + 10 = 45");

            //perform tan(45)
            vm.SingularOperationButtonPress("tan");

            Assert.AreEqual(vm.Display, "1");
            Assert.AreEqual(vm.FullExpression, "tan(45) = 1");
        }
        public void CalculatorViewModel_ConstructorTest()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            Assert.IsTrue(vm.GetType() == typeof(ViewModels.CalculatorViewModel));
            Assert.AreEqual(vm.Display, "0");
            Assert.AreEqual(vm.FirstOperand, string.Empty);
            Assert.AreEqual(vm.SecondOperand, string.Empty);
            Assert.AreEqual(vm.Operation, string.Empty);
            Assert.AreEqual(vm.LastOperation, string.Empty);
            Assert.AreEqual(vm.FullExpression, string.Empty);
        }
        public void CalculatorViewModel_ValidOperationTestThenClear()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            //try -7 + 42 = 35
            vm.DigitButtonPress("7");
            vm.DigitButtonPress("+/-");

            vm.OperationButtonPress("+");
            vm.DigitButtonPress("4");
            vm.DigitButtonPress("2");

            Assert.AreEqual(vm.FirstOperand, "-7");
            Assert.AreEqual(vm.Display, "42");

            //perform operation
            vm.OperationButtonPress("=");

            Assert.AreEqual(vm.Operation, "+");
            Assert.AreEqual(vm.SecondOperand, "42");

            Assert.AreEqual(vm.Display, "35");
            Assert.AreEqual(vm.FullExpression, "-7 + 42 = 35");

            //ClearAll
            vm.DigitButtonPress("C");

            Assert.AreEqual(vm.Display, "0");
            Assert.AreEqual(vm.FirstOperand, string.Empty);
            Assert.AreEqual(vm.SecondOperand, string.Empty);
            Assert.AreEqual(vm.Operation, string.Empty);
            Assert.AreEqual(vm.LastOperation, string.Empty);
            Assert.AreEqual(vm.FullExpression, string.Empty);
        }
        public void CalculatorViewModel_InValidOperationTest()
        {
            ViewModels.CalculatorViewModel vm = new ViewModels.CalculatorViewModel();

            //try -7 + 42 = 35
            vm.DigitButtonPress("7");
            vm.DigitButtonPress("+/-");

            vm.OperationButtonPress("@");
            vm.DigitButtonPress("4");
            vm.DigitButtonPress("2");

            Assert.AreEqual(vm.FirstOperand, "-7");
            Assert.AreEqual(vm.Display, "42");

            try
            {
                //perform operation
                vm.OperationButtonPress("=");
            }
            catch(Exception ex)
            {
                Assert.IsTrue(ex.GetType() == typeof(ArgumentException));
            }

            Assert.AreEqual(vm.Operation, "@");
            Assert.AreEqual(vm.SecondOperand, "42");

            Assert.AreEqual(vm.Display, "Unknown operation: @");
        }
        public CalculatorView()
        {
            InitializeComponent();

            DataContext = new ViewModels.CalculatorViewModel();
        }
 public AddCommandClass(ViewModels.CalculatorViewModel viewModel)
 {
     this._viewModel = viewModel;
 }