Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var bo = new BasicOperations();

            if (bo.Addition(2, 2) == 4)
            {
                Console.WriteLine("Add Test ok");
            }
            if (bo.Subtraction(5, 7) == -2)
            {
                Console.WriteLine("Subtract Test ok");
            }
            if (Math.Abs(bo.Division(5, 2) - double.Parse("2.5")) < 0.1)
            {
                Console.WriteLine("Divide Test ok");
            }
            try
            {
                bo.Division(2, 0);
            }
            catch (ZeroDivisorNotAllowedException e)
            {
                Console.WriteLine("Division by 0 test is ok");
            }
            if (bo.Multiplication(3, 5) == 15)
            {
                Console.WriteLine("Multiplication Test is ok");
            }

            Console.ReadLine();
        }
    private void Awake()
    {
        basicOperations = new BasicOperations();

        operation = Operations.Addition;

        transform.Find("FirstFactor").Find("InputField").GetComponent <InputField>().onEndEdit.AddListener(SetFirstFactor);

        transform.Find("SecondFactor").Find("InputField").GetComponent <InputField>().onEndEdit.AddListener(SetSecondFactor);

        transform.Find("OperationDropdown").GetComponent <Dropdown>().onValueChanged.AddListener(SetOperation);

        transform.Find("ComputeButton").GetComponent <Button>().onClick.AddListener(() =>
        {
            float result = 0;

            switch (operation)
            {
            case Operations.Addition:
                result = basicOperations.Addition(firstFactor, secondFactor);
                break;

            case Operations.Subtraction:
                result = basicOperations.Subtraction(firstFactor, secondFactor);
                break;

            case Operations.Multiplication:
                result = basicOperations.Multiplication(firstFactor, secondFactor);
                break;

            case Operations.Division:
                if (secondFactor == 0)
                {
                    ShowResultMessage("You can't divide by 0!");
                    return;
                }

                result = basicOperations.Division(firstFactor, secondFactor);
                break;
            }

            ShowResult(result);
        });

        resultText = transform.Find("Result").Find("Value").GetComponent <Text>();
    }
Ejemplo n.º 3
0
        private static void Main(string[] args)
        {
            var tester          = new Assert("Basic Operations");
            var basicOperations = new BasicOperations();

            tester.AreEqual("Addition", 10, basicOperations.Addition(5, 5));

            tester.AreEqual("Subtraction", 0, basicOperations.Subtraction(5, 5));

            tester.AreEqual("Division", 1, basicOperations.Division(5, 5));

            tester.ThrowsException <ZeroDivisorNotAllowed>("Zero Division", () => basicOperations.Division(10, 0));

            tester.AreEqual("Multiplication", 25, basicOperations.Multiplication(5, 5));

            Console.ReadKey();
        }
Ejemplo n.º 4
0
 public void MultiplicationEquals(int val1, int val2, int expectedResult)
 {
     Assert.AreEqual(expectedResult, _basicOperations.Multiplication(val1, val2));
 }