Open alexey-malov opened 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");
}
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);
}
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);
}
}