diff --git a/Src/GeneralUtility.cpp b/Src/GeneralUtility.cpp index a9dbf5c..d239804 100644 --- a/Src/GeneralUtility.cpp +++ b/Src/GeneralUtility.cpp @@ -3,14 +3,16 @@ #include #include -// Fast 64-bit int power function -std::uint64_t Powuli(const std::uint64_t& b, const std::uint64_t& e) { - std::uint64_t buf = 1; +namespace { + // Fast 64-bit int power function + inline std::uint64_t Powuli(const std::uint64_t &b, const std::uint64_t &e) { + std::uint64_t buf = 1; - for (std::uint64_t i = 0; i < e; i++) - buf *= b; + for (std::uint64_t i = 0; i < e; i++) + buf *= b; - return buf; + return buf; + } } std::uint64_t GeneralUtility::BaseX_2_10(const std::string& num, const std::string& set) { diff --git a/Test/StringDivision.cpp b/Test/StringDivision.cpp index 50cb0f8..df36ca2 100644 --- a/Test/StringDivision.cpp +++ b/Test/StringDivision.cpp @@ -4,6 +4,7 @@ #include #include #include +#include // Tests that basic division (base10) is working, with oracle values TEST_CASE(__FILE__"/Base10", "[StringDivision]") @@ -130,3 +131,19 @@ TEST_CASE(__FILE__"/BaseFuckingBig", "[StringDivision]") REQUIRE(res.second == 555); } } + +// Tests that a division by zero exception is thrown when appropriate +TEST_CASE(__FILE__"/DivisionByZero", "[StringDivision]") +{ + REQUIRE_THROWS_AS( + GeneralUtility::StringDivision("699", 0) + , std::overflow_error); +} + +// Tests that a logic error is thrown when the supplied set is empty +TEST_CASE(__FILE__"/NoSetSupplied", "[StringDivision]") +{ + REQUIRE_THROWS_AS( + GeneralUtility::StringDivision("699", 5, "") + , std::logic_error); +}