Added tests for string division expecting exceptions
This commit is contained in:
parent
5ff48cb710
commit
a0a77f51fe
@ -3,8 +3,9 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace {
|
||||||
// Fast 64-bit int power function
|
// Fast 64-bit int power function
|
||||||
std::uint64_t Powuli(const std::uint64_t& b, const std::uint64_t& e) {
|
inline std::uint64_t Powuli(const std::uint64_t &b, const std::uint64_t &e) {
|
||||||
std::uint64_t buf = 1;
|
std::uint64_t buf = 1;
|
||||||
|
|
||||||
for (std::uint64_t i = 0; i < e; i++)
|
for (std::uint64_t i = 0; i < e; i++)
|
||||||
@ -12,6 +13,7 @@ std::uint64_t Powuli(const std::uint64_t& b, const std::uint64_t& e) {
|
|||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::uint64_t GeneralUtility::BaseX_2_10(const std::string& num, const std::string& set) {
|
std::uint64_t GeneralUtility::BaseX_2_10(const std::string& num, const std::string& set) {
|
||||||
unsigned long long int buf = 0;
|
unsigned long long int buf = 0;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
// Tests that basic division (base10) is working, with oracle values
|
// Tests that basic division (base10) is working, with oracle values
|
||||||
TEST_CASE(__FILE__"/Base10", "[StringDivision]")
|
TEST_CASE(__FILE__"/Base10", "[StringDivision]")
|
||||||
@ -130,3 +131,19 @@ TEST_CASE(__FILE__"/BaseFuckingBig", "[StringDivision]")
|
|||||||
REQUIRE(res.second == 555);
|
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);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user