コード例 #1
0
        // Vetting the inverse of the results division
        private bool CheckDivision(Fraction.Fraction first, Fraction.Fraction second)
        {
            // Saving the original data
            Fraction.Fraction firstFraction  = first;
            Fraction.Fraction secondFraction = second;
            System.Console.Write("\n" + fractionCalulator.ReducedFraction(firstFraction).GetNumerator().ToString() + '/' + fractionCalulator.ReducedFraction(firstFraction).GetDenominator().ToString()
                                 + " / " + fractionCalulator.ReducedFraction(secondFraction).GetNumerator().ToString() + '/' + fractionCalulator.ReducedFraction(secondFraction).GetDenominator().ToString());

            // Grab the results from the calculator
            // MODIFY: Changing method to something else will produce failed test cases
            //Fraction.Fraction actualResults = fractionCalulator.Addition(first, second);
            Fraction.Fraction actualResults = fractionCalulator.Division(first, second);
            System.Console.Write(" = " + actualResults.GetNumerator().ToString() + '/' + actualResults.GetDenominator().ToString());

            // actual results turns out to be a non-real fraction so pass it
            if (actualResults.GetDenominator() == 0 && second.GetNumerator() == 0)
            {
                return(true);
            }


            // Run the inverse operations of the function to pull the expected results
            Fraction.Fraction expectedResults = new Fraction.Fraction();
            expectedResults.SetDenominator(actualResults.GetDenominator() / second.GetNumerator());
            expectedResults.SetNumerator(actualResults.GetNumerator() / second.GetDenominator());

            // Compare
            if ((expectedResults.GetNumerator() == firstFraction.GetNumerator()) && (expectedResults.GetDenominator() == firstFraction.GetDenominator()))
            {
                return(true);
            }

            // if numerators are both 0, the value is 0
            else if ((expectedResults.GetNumerator() == 0) && (expectedResults.GetNumerator() == 0))
            {
                return(true);
            }

            else
            {
                // try reducing both fractions and check for failing
                expectedResults = fractionCalulator.ReducedFraction(expectedResults);
                firstFraction   = fractionCalulator.ReducedFraction(firstFraction);
                if ((expectedResults.GetNumerator() == firstFraction.GetNumerator()) && (expectedResults.GetDenominator() == firstFraction.GetDenominator()))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        // Vetting the inverse of the results addition
        private bool CheckAddition(Fraction.Fraction first, Fraction.Fraction second)
        {
            // Saving the original data
            Fraction.Fraction firstFraction  = first;
            Fraction.Fraction secondFraction = second;
            System.Console.Write("\n" + fractionCalulator.ReducedFraction(firstFraction).GetNumerator().ToString() + '/' + fractionCalulator.ReducedFraction(firstFraction).GetDenominator().ToString()
                                 + " + " + fractionCalulator.ReducedFraction(secondFraction).GetNumerator().ToString() + '/' + fractionCalulator.ReducedFraction(secondFraction).GetDenominator().ToString());

            // Grab the results from the calculator,
            // MODIFY: Changing method to something else will produce failed test cases
            // Fraction.Fraction actualResults = fractionCalulator.Subtractive(first, second);
            Fraction.Fraction actualResults = fractionCalulator.Addition(first, second);
            System.Console.Write(" = " + fractionCalulator.ReducedFraction(actualResults).GetNumerator().ToString() + '/' + fractionCalulator.ReducedFraction(actualResults).GetDenominator().ToString());

            // Run the inverse function of the calculator to pull the expected results
            Fraction.Fraction expectedResult = fractionCalulator.Subtraction(actualResults, secondFraction);

            // Compare
            if ((expectedResult.GetNumerator() == firstFraction.GetNumerator()) && (expectedResult.GetDenominator() == firstFraction.GetDenominator()))
            {
                return(true);
            }
            // if numerators are both 0, the value is 0
            else if ((expectedResult.GetNumerator() == 0) && (expectedResult.GetNumerator() == 0))
            {
                return(true);
            }
            else
            {
                // try reducting both fractions and check for failing
                expectedResult = fractionCalulator.ReducedFraction(expectedResult);
                firstFraction  = fractionCalulator.ReducedFraction(firstFraction);
                if ((expectedResult.GetNumerator() == firstFraction.GetNumerator()) && (expectedResult.GetDenominator() == firstFraction.GetDenominator()))
                {
                    return(true);
                }
            }
            return(false);
        }