private void Calculate_Button_Click(object sender, RoutedEventArgs e)
        {
            if (ComboBox_Operation.SelectedItem == null ||
                string.IsNullOrEmpty(TextBox_InitialOperand_1.Text) ||
                string.IsNullOrEmpty(TextBox_InitialOperand_2.Text))
            {
                MessageBox.Show("Missing data in fields!");
            }
            else
            {
                Operations           operation           = (Operations)ComboBox_Operation.SelectedItem;
                MachineCodeValidator validator_operand_1 = new MachineCodeValidator(TextBox_InitialOperand_1.Text);
                MachineCodeValidator validator_operand_2 = new MachineCodeValidator(TextBox_InitialOperand_2.Text);

                if (!validator_operand_1.isValidate())
                {
                    MessageBox.Show("First operand is not validate to machine representation of the code!");
                }
                else
                if (!validator_operand_2.isValidate())
                {
                    MessageBox.Show("Second operand is not validate to machine representation of the code!");
                }
                else
                {
                    var machine_code_1      = validator_operand_1.GetMachineCode();
                    var machine_code_2      = validator_operand_2.GetMachineCode();
                    var result_machine_code = MachineCalculator.Solve(machine_code_1, machine_code_2, operation);

                    Calculated_TextBlock.Text =
                        result_machine_code != null?result_machine_code.ToString() : "null";
                }
            }
        }
Exemplo n.º 2
0
        public void Plus_1()
        {
            MachineCode code_1 = new MachineCode("0 1111000 11001");
            MachineCode code_2 = new MachineCode("0 1111000 110100");

            var result_code = MachineCalculator.Plus(code_1, code_2);

            Assert.AreEqual("0 1111000 1001101", result_code.ToString());
        }