fix(tests): vector<pair>
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <base/base64.hpp>
|
#include <base/base64.hpp>
|
||||||
#include <base/hex.hpp>
|
#include <base/hex.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@ -6,19 +8,26 @@ using namespace base64;
|
|||||||
|
|
||||||
TEST(base64, isValid)
|
TEST(base64, isValid)
|
||||||
{
|
{
|
||||||
EXPECT_TRUE(isValid("12=="));
|
std::vector<std::pair<bool, std::string>> tests = {
|
||||||
EXPECT_TRUE(isValid("123="));
|
{true, "12=="},
|
||||||
EXPECT_TRUE(isValid("1234"));
|
{true, "123="},
|
||||||
|
{true, "1234"},
|
||||||
EXPECT_FALSE(isValid("1==="));
|
{false, "1==="},
|
||||||
EXPECT_FALSE(isValid("?!*"));
|
{false, "?!*"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(it.first, isValid(it.second));
|
||||||
}
|
}
|
||||||
TEST(base64, encode)
|
TEST(base64, encode)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(encode(hex::decode("")), "");
|
std::vector<std::pair<std::string, std::string>> tests = {
|
||||||
EXPECT_EQ(encode(hex::decode("04a504a5")), "BKUEpQ==");
|
{"", ""},
|
||||||
EXPECT_EQ(encode(hex::decode("04a504a500")), "BKUEpQA=");
|
{"BKUEpQ==", "04a504a5"},
|
||||||
EXPECT_EQ(encode(hex::decode("04a504a50000")), "BKUEpQAA");
|
{"BKUEpQA=", "04a504a500"},
|
||||||
|
{"BKUEpQAA", "04a504a50000"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(it.first, encode(hex::decode(it.second)));
|
||||||
}
|
}
|
||||||
TEST(base64, encode_1e7)
|
TEST(base64, encode_1e7)
|
||||||
{
|
{
|
||||||
@ -27,10 +36,14 @@ TEST(base64, encode_1e7)
|
|||||||
}
|
}
|
||||||
TEST(base64, decode)
|
TEST(base64, decode)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(hex::encode(decode("")), "");
|
std::vector<std::pair<std::string, std::string>> tests = {
|
||||||
EXPECT_EQ(hex::encode(decode("BKUEpQ==")), "04a504a5");
|
{"", ""},
|
||||||
EXPECT_EQ(hex::encode(decode("BKUEpQA=")), "04a504a500");
|
{"BKUEpQ==", "04a504a5"},
|
||||||
EXPECT_EQ(hex::encode(decode("BKUEpQAA")), "04a504a50000");
|
{"BKUEpQA=", "04a504a500"},
|
||||||
|
{"BKUEpQAA", "04a504a50000"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(hex::encode(decode(it.first)), it.second);
|
||||||
}
|
}
|
||||||
TEST(base64, decode_1e7)
|
TEST(base64, decode_1e7)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#include <utility>
|
||||||
|
|
||||||
#include <base/baseN.hpp>
|
#include <base/baseN.hpp>
|
||||||
#include <base/hex.hpp>
|
#include <base/hex.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
@ -29,17 +31,25 @@ static const int8_t b58map[] = {
|
|||||||
|
|
||||||
TEST(baseN, isValid)
|
TEST(baseN, isValid)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(true, isValid("123", b58map));
|
std::vector<std::pair<bool, std::string>> tests = {
|
||||||
EXPECT_EQ(false, isValid("@#$", b58map));
|
{true, "123"},
|
||||||
|
{false, "@#$"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(it.first, isValid(it.second, b58map));
|
||||||
}
|
}
|
||||||
TEST(baseN, encode)
|
TEST(baseN, encode)
|
||||||
{
|
{
|
||||||
EXPECT_EQ("", encode(hex::decode(""), 58, b58digits));
|
std::vector<std::pair<std::string, std::string>> tests = {
|
||||||
EXPECT_EQ("Ky", encode(hex::decode("044c"), 58, b58digits));
|
{"", ""},
|
||||||
EXPECT_EQ("KyK", encode(hex::decode("f94a"), 58, b58digits));
|
{"Ky", "044c"},
|
||||||
EXPECT_EQ("KyKX", encode(hex::decode("387ae2"), 58, b58digits));
|
{"KyK", "f94a"},
|
||||||
EXPECT_EQ("KyKXa", encode(hex::decode("0ccbd755"), 58, b58digits));
|
{"KyKX", "387ae2"},
|
||||||
EXPECT_EQ("KyKXaa", encode(hex::decode("02e62ec963"), 58, b58digits));
|
{"KyKXa", "0ccbd755"},
|
||||||
|
{"KyKXaa", "02e62ec963"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(it.first, encode(hex::decode(it.second), 58, b58digits));
|
||||||
}
|
}
|
||||||
TEST(baseN, encode_1e3)
|
TEST(baseN, encode_1e3)
|
||||||
{
|
{
|
||||||
@ -49,12 +59,16 @@ TEST(baseN, encode_1e3)
|
|||||||
}
|
}
|
||||||
TEST(baseN, decode)
|
TEST(baseN, decode)
|
||||||
{
|
{
|
||||||
EXPECT_EQ(hex::encode(decode("", 58, b58digits, b58map)), "");
|
std::vector<std::pair<std::string, std::string>> tests = {
|
||||||
EXPECT_EQ(hex::encode(decode("Ky", 58, b58digits, b58map)), "044c");
|
{"", ""},
|
||||||
EXPECT_EQ(hex::encode(decode("KyK", 58, b58digits, b58map)), "f94a");
|
{"Ky", "044c"},
|
||||||
EXPECT_EQ(hex::encode(decode("KyKX", 58, b58digits, b58map)), "387ae2");
|
{"KyK", "f94a"},
|
||||||
EXPECT_EQ(hex::encode(decode("KyKXa", 58, b58digits, b58map)), "0ccbd755");
|
{"KyKX", "387ae2"},
|
||||||
EXPECT_EQ(hex::encode(decode("KyKXaa", 58, b58digits, b58map)), "02e62ec963");
|
{"KyKXa", "0ccbd755"},
|
||||||
|
{"KyKXaa", "02e62ec963"},
|
||||||
|
};
|
||||||
|
for (auto it : tests)
|
||||||
|
EXPECT_EQ(hex::encode(decode(it.first, 58, b58digits, b58map)), it.second);
|
||||||
}
|
}
|
||||||
TEST(baseN, decode_1e3)
|
TEST(baseN, decode_1e3)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user