fix(tests): vector<pair>

This commit is contained in:
2024-09-18 23:41:14 +03:00
parent 961e54c08b
commit 5822443706
2 changed files with 55 additions and 28 deletions

View File

@ -1,3 +1,5 @@
#include <utility>
#include <base/base64.hpp>
#include <base/hex.hpp>
#include <gtest/gtest.h>
@ -6,19 +8,26 @@ using namespace base64;
TEST(base64, isValid)
{
EXPECT_TRUE(isValid("12=="));
EXPECT_TRUE(isValid("123="));
EXPECT_TRUE(isValid("1234"));
EXPECT_FALSE(isValid("1==="));
EXPECT_FALSE(isValid("?!*"));
std::vector<std::pair<bool, std::string>> tests = {
{true, "12=="},
{true, "123="},
{true, "1234"},
{false, "1==="},
{false, "?!*"},
};
for (auto it : tests)
EXPECT_EQ(it.first, isValid(it.second));
}
TEST(base64, encode)
{
EXPECT_EQ(encode(hex::decode("")), "");
EXPECT_EQ(encode(hex::decode("04a504a5")), "BKUEpQ==");
EXPECT_EQ(encode(hex::decode("04a504a500")), "BKUEpQA=");
EXPECT_EQ(encode(hex::decode("04a504a50000")), "BKUEpQAA");
std::vector<std::pair<std::string, std::string>> tests = {
{"", ""},
{"BKUEpQ==", "04a504a5"},
{"BKUEpQA=", "04a504a500"},
{"BKUEpQAA", "04a504a50000"},
};
for (auto it : tests)
EXPECT_EQ(it.first, encode(hex::decode(it.second)));
}
TEST(base64, encode_1e7)
{
@ -27,10 +36,14 @@ TEST(base64, encode_1e7)
}
TEST(base64, decode)
{
EXPECT_EQ(hex::encode(decode("")), "");
EXPECT_EQ(hex::encode(decode("BKUEpQ==")), "04a504a5");
EXPECT_EQ(hex::encode(decode("BKUEpQA=")), "04a504a500");
EXPECT_EQ(hex::encode(decode("BKUEpQAA")), "04a504a50000");
std::vector<std::pair<std::string, std::string>> tests = {
{"", ""},
{"BKUEpQ==", "04a504a5"},
{"BKUEpQA=", "04a504a500"},
{"BKUEpQAA", "04a504a50000"},
};
for (auto it : tests)
EXPECT_EQ(hex::encode(decode(it.first)), it.second);
}
TEST(base64, decode_1e7)
{

View File

@ -1,3 +1,5 @@
#include <utility>
#include <base/baseN.hpp>
#include <base/hex.hpp>
#include <gtest/gtest.h>
@ -29,17 +31,25 @@ static const int8_t b58map[] = {
TEST(baseN, isValid)
{
EXPECT_EQ(true, isValid("123", b58map));
EXPECT_EQ(false, isValid("@#$", b58map));
std::vector<std::pair<bool, std::string>> tests = {
{true, "123"},
{false, "@#$"},
};
for (auto it : tests)
EXPECT_EQ(it.first, isValid(it.second, b58map));
}
TEST(baseN, encode)
{
EXPECT_EQ("", encode(hex::decode(""), 58, b58digits));
EXPECT_EQ("Ky", encode(hex::decode("044c"), 58, b58digits));
EXPECT_EQ("KyK", encode(hex::decode("f94a"), 58, b58digits));
EXPECT_EQ("KyKX", encode(hex::decode("387ae2"), 58, b58digits));
EXPECT_EQ("KyKXa", encode(hex::decode("0ccbd755"), 58, b58digits));
EXPECT_EQ("KyKXaa", encode(hex::decode("02e62ec963"), 58, b58digits));
std::vector<std::pair<std::string, std::string>> tests = {
{"", ""},
{"Ky", "044c"},
{"KyK", "f94a"},
{"KyKX", "387ae2"},
{"KyKXa", "0ccbd755"},
{"KyKXaa", "02e62ec963"},
};
for (auto it : tests)
EXPECT_EQ(it.first, encode(hex::decode(it.second), 58, b58digits));
}
TEST(baseN, encode_1e3)
{
@ -49,12 +59,16 @@ TEST(baseN, encode_1e3)
}
TEST(baseN, decode)
{
EXPECT_EQ(hex::encode(decode("", 58, b58digits, b58map)), "");
EXPECT_EQ(hex::encode(decode("Ky", 58, b58digits, b58map)), "044c");
EXPECT_EQ(hex::encode(decode("KyK", 58, b58digits, b58map)), "f94a");
EXPECT_EQ(hex::encode(decode("KyKX", 58, b58digits, b58map)), "387ae2");
EXPECT_EQ(hex::encode(decode("KyKXa", 58, b58digits, b58map)), "0ccbd755");
EXPECT_EQ(hex::encode(decode("KyKXaa", 58, b58digits, b58map)), "02e62ec963");
std::vector<std::pair<std::string, std::string>> tests = {
{"", ""},
{"Ky", "044c"},
{"KyK", "f94a"},
{"KyKX", "387ae2"},
{"KyKXa", "0ccbd755"},
{"KyKXaa", "02e62ec963"},
};
for (auto it : tests)
EXPECT_EQ(hex::encode(decode(it.first, 58, b58digits, b58map)), it.second);
}
TEST(baseN, decode_1e3)
{