Added tests for string division expecting exceptions

This commit is contained in:
Leonetienne 2022-02-27 15:55:47 +01:00
parent 5ff48cb710
commit a0a77f51fe
2 changed files with 25 additions and 6 deletions

View File

@ -3,14 +3,16 @@
#include <sstream>
#include <stdexcept>
// 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) {

View File

@ -4,6 +4,7 @@
#include <vector>
#include <time.h>
#include <sstream>
#include <stdexcept>
// 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);
}