Added Base10_2_X wrapper, and tests

This commit is contained in:
Leonetienne
2022-02-27 17:08:57 +01:00
parent 932bd62477
commit eaa406c9e6
4 changed files with 99 additions and 1 deletions

77
Test/Base10_2_X.cpp Normal file
View File

@@ -0,0 +1,77 @@
#include <GeneralUtility.h>
#include "Catch2.h"
// Tests base 10 to 10
TEST_CASE(__FILE__"/Base10_to_10", "[Base10_2_X]")
{
// Setup
const std::string set = "0123456789";
const std::uint64_t in = 1990381;
const std::string expected_out = "1990381";
// Exercise
const std::string out = GeneralUtility::Base10_2_X(in, set);
// Verify
REQUIRE(out == expected_out);
}
// Tests base 10 to 16
TEST_CASE(__FILE__"/Base10_to_16", "[Base10_2_X]")
{
// Setup
const std::string set = "0123456789abcdef";
const std::uint64_t in = 0x1990381;
const std::string expected_out = "1990381";
// Exercise
const std::string out = GeneralUtility::Base10_2_X(in, set);
// Verify
REQUIRE(out == expected_out);
}
// Tests base 10 to 2
TEST_CASE(__FILE__"/Base10_to_2", "[Base10_2_X]")
{
// Setup
const std::string set = "01";
const std::uint64_t in = 0b10111011;
const std::string expected_out = "10111011";
// Exercise
const std::string out = GeneralUtility::Base10_2_X(in, set);
// Verify
REQUIRE(out == expected_out);
}
// Tests base 10 to fucking big
TEST_CASE(__FILE__"/Base10_to_FuckingBig", "[Base10_2_X]")
{
// Setup
const std::string set = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const std::uint64_t in = 189434143264827;
const std::string expected_out = "rn5qZuTD";
// Exercise
const std::string out = GeneralUtility::Base10_2_X(in, set);
// Verify
REQUIRE(out == expected_out);
}
// Tests that padding works
TEST_CASE(__FILE__"/TestPadding", "[Base10_2_X]")
{
// Setup
const std::string set = "01";
const std::uint64_t in = 0b101;
const std::string expected_out = "00000101";
// Exercise
const std::string out = GeneralUtility::Base10_2_X(in, set, 8);
// Verify
REQUIRE(out == expected_out);
}

View File

@@ -13,6 +13,7 @@ add_executable(Test
Ord.cpp
StringDivision.cpp
BaseX_2_10.cpp
Base10_2_X.cpp
BaseX_2_Y.cpp
)