Romasmi / cpp-practice

0 stars 0 forks source link

Замечания по Rational #20

Closed alexey-malov closed 5 years ago

alexey-malov commented 5 years ago
1>c:\teaching\ips\2019\smirnov\cpp_oop_practice\lab_5\c_rational\crational.h(75): warning C4227: anachronism used: qualifiers on reference are ignored
1>c:\teaching\ips\2019\smirnov\cpp_oop_practice\lab_5\c_rational\crational.h(76): warning C4227: anachronism used: qualifiers on reference are ignored
alexey-malov commented 5 years ago

image

alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
void CRational::Normalize()
{
    const int gcd = GCD(m_numerator, m_denominator);
    m_numerator /= gcd;
    m_denominator /= gcd;
}
alexey-malov commented 5 years ago
CRational const operator+(const int n1, const CRational& n2)
{
    return CRational(n1) + n2;
}

CRational const operator+(const CRational& n1, const int n2)
{
    return CRational(n2) + n1;
}
alexey-malov commented 5 years ago
SCENARIO("check boolean !=")
{
    WHEN("check inequality of 1/2 and 1/2")
    {
        CRational n1(1, 2);
        CRational n2(1, 2);

        THEN("it returns false")
alexey-malov commented 5 years ago
CRational::CRational(const int numerator, const int denominator)
    : m_numerator(numerator)
    , m_denominator(denominator)
{
    if (m_denominator == 0)
    {
        throw std::overflow_error("Divide by zero exception");
    }
    Normalize();
}
alexey-malov commented 5 years ago
alexey-malov commented 5 years ago
std::pair<int, CRational> CRational::ToCompoundFraction() const
{
    const int intPart = (int)(floor(abs(ToDouble())));
    const int remainder = intPart * GetDenominator();
alexey-malov commented 5 years ago
    WHEN("convert negative retional number with intPart")
    {
        CRational n(-9, 5);
        THEN("get intPart and negative normal rational number")
        {
            REQUIRE(n.ToCompoundFraction() == make_pair<int, CRational>(1, CRational(-4, 5)));
        }
    }