public void ShouldPowerFraction()
        {
            var fractionResponse = new FractionResponse { Fraction = new FractionModel { Numerator = 8, Denominator = 27 } };
            _client.Expect(c => c.Power(2, 3, 3)).Return(fractionResponse);

            var result = _helper.ParseExpression("2/3 ^ 3");

            Assert.IsNotNull(result);
            Assert.AreEqual("8/27", result);
        }
        public void ShouldDivide2Fractions()
        {
            var fractionResponse = new FractionResponse { Fraction = new FractionModel { Numerator = 5, Denominator = 6 } };
            _client.Expect(c => c.Divide(2, 3, 4, 5)).Return(fractionResponse);

            var result = _helper.ParseExpression("2/3 / 4/5");

            Assert.IsNotNull(result);
            Assert.AreEqual("5/6", result);
        }
        public void ShouldMultiply2Fractions()
        {
            var fractionResponse = new FractionResponse { Fraction = new FractionModel { Numerator = 8, Denominator = 15 } };
            _client.Expect(c => c.Multiply(2, 3, 4, 5)).Return(fractionResponse);

            var result = _helper.ParseExpression("2/3 * 4/5");

            Assert.IsNotNull(result);
            Assert.AreEqual("8/15", result);
        }
        public void ShouldSubtractTwoFractionsCallingFractionServiceWebApi()
        {
            FractionModel fraction = new FractionModel { Numerator = 1, Denominator = 6 };

            FractionResponse fractionResponse = new FractionResponse { Fraction = fraction };

            var response = new RestResponse<FractionResponse> { Data = fractionResponse, StatusCode = HttpStatusCode.OK };

            _restClient.Expect(
                rc =>
                    rc.Execute<FractionResponse>(
                        Arg<RestRequest>.Matches(
                            rr => rr.Method == Method.POST && rr.Resource.Equals("api/Fractions/Subtract"))))
                .Return(response);

            var result = _client.Subtract(1, 2, 1, 3);

            _restClient.VerifyAllExpectations();

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Fraction.Numerator);
            Assert.AreEqual(6, result.Fraction.Denominator);
        }
        public void ShouldReturnIntegerWhenOperatingOnFractions()
        {
            var fractionResponse = new FractionResponse { Fraction = new FractionModel { Numerator = 2, Denominator = 1 } };
            _client.Expect(c => c.Multiply(2, 3, 3, 1)).Return(fractionResponse);

            var result = _helper.ParseExpression("2/3 * 3");

            Assert.IsNotNull(result);
            Assert.AreEqual("2", result);
        }
 private string FractionToString(FractionResponse response)
 {
     if (response.Fraction.Denominator == 1)
         return $"{response.Fraction.Numerator}";
     return $"{response.Fraction.Numerator}/{response.Fraction.Denominator}";
 }