From 8217e95e8555d11d771bee9bd9e0e2b8bd59f36e Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Wed, 11 Sep 2024 17:11:51 +0300 Subject: [PATCH] feat(hex): test --- Makefile | 1 + src/hex.cpp | 2 +- test/test-hex.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/test-hex.cpp diff --git a/Makefile b/Makefile index 91c9a03..2a3fa0d 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ OBJS =\ TOOLS =\ TESTS =\ + test-hex\ ifeq (${origin CC}, default) CC = g++ diff --git a/src/hex.cpp b/src/hex.cpp index 39dee34..525dac2 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -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, }; -namespace btc::data +namespace hex { bool isValid(const std::string &str) noexcept { diff --git a/test/test-hex.cpp b/test/test-hex.cpp new file mode 100644 index 0000000..85c21e0 --- /dev/null +++ b/test/test-hex.cpp @@ -0,0 +1,31 @@ +#include +#include + +using namespace hex; + +TEST(hex, encode) +{ + std::vector data = { 0x74, 0x65, 0x73, 0x74 }; + EXPECT_EQ("74657374", encode(data)); +} +TEST(hex, encode_1e6) +{ + std::vector data(1e6); + encode(data); +} +TEST(hex, decode) +{ + std::vector 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(); +} \ No newline at end of file