feat(hex): test

This commit is contained in:
2024-09-11 17:11:51 +03:00
parent 17e2e04a3b
commit 8217e95e85
3 changed files with 33 additions and 1 deletions

View File

@ -15,6 +15,7 @@ OBJS =\
TOOLS =\ TOOLS =\
TESTS =\ TESTS =\
test-hex\
ifeq (${origin CC}, default) ifeq (${origin CC}, default)
CC = g++ CC = g++

View File

@ -23,7 +23,7 @@ static const int8_t hexmap[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
}; };
namespace btc::data namespace hex
{ {
bool isValid(const std::string &str) noexcept bool isValid(const std::string &str) noexcept
{ {

31
test/test-hex.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <base/hex.hpp>
#include <gtest/gtest.h>
using namespace hex;
TEST(hex, encode)
{
std::vector<uint8_t> data = { 0x74, 0x65, 0x73, 0x74 };
EXPECT_EQ("74657374", encode(data));
}
TEST(hex, encode_1e6)
{
std::vector<uint8_t> data(1e6);
encode(data);
}
TEST(hex, decode)
{
std::vector<uint8_t> data = { 0x61, 0x6e, 0x6f };
EXPECT_EQ(decode("616e6f"), data);
}
TEST(hex, decode_1e6)
{
std::string str(1e6, '0');
decode(str);
}
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}