Esempio n. 1
0
        public void CalculationInValid1()
        {
            //arrange

            Fraction test = new Fraction("1/3");
            Fraction test2 = new Fraction("0");

            //act

            var result = FractionCalculator.Div(test, test2);

            //assert
        }
Esempio n. 2
0
        public void CalculationValid4()
        {
            //arrange

            Fraction test = new Fraction("-1/3");
            Fraction test2 = new Fraction("-1/2");

            //act

            var result = FractionCalculator.Div(test, test2);

            //assert
            Assert.AreEqual(2, result.Numerator);
            Assert.AreEqual(3, result.Denominator);
        }
Esempio n. 3
0
        public void CalculationValid3()
        {
            //arrange

            Fraction test = new Fraction("2/3");
            Fraction test2 = new Fraction("3/2");

            //act

            var result = FractionCalculator.Mul(test, test2);

            //assert
            Assert.AreEqual(1, result.Numerator);
            Assert.AreEqual(1, result.Denominator);
        }
Esempio n. 4
0
        public void CalculationValid2()
        {
            //arrange

            Fraction test = new Fraction("1/3");
            Fraction test2 = new Fraction("1/2");

            //act

            var result = FractionCalculator.Sub(test, test2);

            //assert
            Assert.AreEqual(-1, result.Numerator);
            Assert.AreEqual(6, result.Denominator);
        }
Esempio n. 5
0
 public static Fraction Sub(Fraction arg1, Fraction arg2)
 {
     Fraction minusOne = new Fraction("-1/1");
     Fraction result = (Add(arg1, Mul(minusOne, arg2)));
     result.OptimizeFraction();
     return result;
 }
Esempio n. 6
0
 public static Fraction Mul(Fraction arg1, Fraction arg2)
 {
     Fraction result = new Fraction((arg1.Numerator * arg2.Numerator).ToString() + "/" + (arg1.Denominator * arg2.Denominator).ToString());
     result.OptimizeFraction();
     return result;
 }
Esempio n. 7
0
        public static Fraction Div(Fraction arg1, Fraction arg2)
        {
            if (arg2.Numerator == 0)
                throw new DivideByZeroException();

            Fraction result = new Fraction((arg1.Numerator*arg2.Denominator).ToString()+"/"+(arg1.Denominator*arg2.Numerator).ToString());
            result.OptimizeFraction();
            return result;
        }
Esempio n. 8
0
        public void InputCorrect1()
        {
            //arrange

            Fraction test = new Fraction("11");

            //assert
            Assert.AreEqual(11, test.Numerator);
            Assert.AreEqual(1, test.Denominator);
        }
Esempio n. 9
0
        public void InputException4()
        {
            //arrange

            Fraction test = new Fraction("11/11/1");
        }
Esempio n. 10
0
        public void InputCorrect4()
        {
            //arrange

            Fraction test = new Fraction("-11/12");

            //assert
            Assert.AreEqual(-11, test.Numerator);
            Assert.AreEqual(12, test.Denominator);
        }