Relz / OOP

Лабораторные работы по Объектно-ориентированному программированию (IDE - Visual Studio 2015)
0 stars 0 forks source link

Замечания по CRational #10

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
2>c:\teaching\2016\new\starovoytov\oop\lab_5\rational\rational.cpp(37): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
2>c:\teaching\2016\new\starovoytov\oop\lab_5\rational\rational.cpp(37): warning C4267: 'initializing': conversion from 'size_t' to 'const int', possible loss of data
2>c:\teaching\2016\new\starovoytov\oop\lab_5\rational\rational.cpp(93): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
2>c:\teaching\2016\new\starovoytov\oop\lab_5\rational\rational.cpp(104): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data
alexey-malov commented 7 years ago
    try
    {
        return stoi(resultStr);
    }
    catch (std::out_of_range)
    {
        throw std::out_of_range("Numerator is too big");
    }
    try
    {
        return stoi(resultStr);
    }
    catch (std::out_of_range)
    {
        throw std::out_of_range("Denominator is too big");
    }
alexey-malov commented 7 years ago

image

alexey-malov commented 7 years ago
    BOOST_AUTO_TEST_CASE(must_have_a_valid_addition_assignment)
    {
        int x = 3, y = 5, z = 6;
        (x += y) += z;

        CRational rx(3);
        CRational ry(5);
        CRational rz(6);
        (rx += ry) += rz;
        BOOST_CHECK(rx == x);
    }
alexey-malov commented 7 years ago
    BOOST_AUTO_TEST_CASE(can_be_initialized_from_istream)
    {
        {
            std::stringstream input("3/4");
            CRational r;
            input >> r;
            VerifyRational(r, 3, 4);
        }
        {
            std::stringstream input("-3/4");
            CRational r;
            input >> r;
            VerifyRational(r, -3, 4);
        }
        {
            std::stringstream input("+3/4");
            CRational r;
            input >> r;
            VerifyRational(r, -3, 4);
        }

    }