diff --git a/2022/25.cpp b/2022/25.cpp index 633b450..013117e 100644 --- a/2022/25.cpp +++ b/2022/25.cpp @@ -19,7 +19,7 @@ auto DivMod(T dividend, T divisor) -> std::pair { auto const quotient = dividend / divisor; auto const remainder = dividend % divisor; - if ((remainder >= 0) == (divisor >= 0)) { + if (remainder == 0 || (remainder > 0) == (divisor > 0)) { return {quotient, remainder}; } else { return {quotient - 1, remainder + divisor}; @@ -101,6 +101,11 @@ TEST_SUITE("2022-25 examples") { CHECK(DivMod(-2,5) == std::make_pair(-1,3)); CHECK(DivMod(2,-5) == std::make_pair(-1,-3)); CHECK(DivMod(-2,-5) == std::make_pair(0,-2)); + + CHECK(DivMod(-5,-5) == std::make_pair(1,0)); + CHECK(DivMod(-5,5) == std::make_pair(-1,0)); + CHECK(DivMod(5,-5) == std::make_pair(-1,0)); + CHECK(DivMod(-5,-5) == std::make_pair(1,0)); } }