mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-08-17 01:28:14 +02:00
tests/base58/is_base58.cpp: add subcase and fix test structs.
This commit is contained in:
parent
e712d4ec4d
commit
12a3be919a
1 changed files with 29 additions and 29 deletions
|
|
@ -3,50 +3,50 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
|
||||||
typedef std::pair<std::string, size_t> testpair_t;
|
|
||||||
typedef std::vector<testpair_t> tests;
|
|
||||||
|
|
||||||
TEST_CASE("base58::is_base58 [string]") {
|
TEST_CASE("base58::is_base58 [string]") {
|
||||||
tests input = {
|
|
||||||
// Empty string is a valid base58 string.
|
|
||||||
testpair_t("", std::string::npos),
|
|
||||||
|
|
||||||
// Test Zero (0)
|
struct testcase{
|
||||||
testpair_t("2SdasxuGGdVU5VVyrXiko4jKASeS57E0P9uokzUphZt7tZxt24bzsEwvre", 31),
|
const char *name;
|
||||||
|
std::string input;
|
||||||
// Test O
|
size_t expected;
|
||||||
testpair_t("2RTAsaYN2fpxVEDzaQht8ZnAUmwRpJz9C18VXrAWypxQSijRb9295kw13MA8krpRzK5cj2N5p84qQh3OGJrucW8hkLNy3aaEd2rTVhYkekhFiQoQ41JiNScD5KjmpDDxy", 79),
|
|
||||||
|
|
||||||
// Test I
|
|
||||||
testpair_t("5hWrCBA55zLmKpIhZd3RS1DHsJ7SnZpnyBfmibqGpDCJ7QCJGkogvhqPvGuwMgwNHzuZFyR", 14),
|
|
||||||
|
|
||||||
// Test l
|
|
||||||
testpair_t("lHxVA2fQKawLAK9MCJSr2xaWyDpoquQxVP6MMchdhzY49TjTfti8LDR6YL", 0),
|
|
||||||
|
|
||||||
// All valid
|
|
||||||
testpair_t("2BCoJ2BqNWorSoQcSWCQNanB8teoKFaqjojWGEXPBCPPdoGyVN8dgmKRdw", std::string::npos),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for(tests::const_iterator it = input.begin(); it != input.end(); it++) {
|
std::vector<struct testcase> tests = {
|
||||||
|
{"empty", "", std::string::npos},
|
||||||
|
{"zero", "2SdasxuGGdVU5VVyrXiko4jKASeS57E0P9uokzUphZt7tZxt24bzsEwvre", 31},
|
||||||
|
{"O", "2RTAsaYN2fpxVEDzaQht8ZnAUmwRpJz9C18VXrAWypxQSijRb9295kw13MA8krpRzK5cj2N5p84qQh3OGJrucW8hkLNy3aaEd2rTVhYkekhFiQoQ41JiNScD5KjmpDDxy", 79},
|
||||||
|
{"I", "5hWrCBA55zLmKpIhZd3RS1DHsJ7SnZpnyBfmibqGpDCJ7QCJGkogvhqPvGuwMgwNHzuZFyR", 14},
|
||||||
|
{"l", "lHxVA2fQKawLAK9MCJSr2xaWyDpoquQxVP6MMchdhzY49TjTfti8LDR6YL", 0},
|
||||||
|
{"all_valid", "2BCoJ2BqNWorSoQcSWCQNanB8teoKFaqjojWGEXPBCPPdoGyVN8dgmKRdw", std::string::npos},
|
||||||
|
};
|
||||||
|
|
||||||
size_t ret = libeosio::is_base58(it->first);
|
for(auto it = tests.begin(); it != tests.end(); it++) {
|
||||||
|
|
||||||
|
SUBCASE(it->name) {
|
||||||
|
CHECK(libeosio::is_base58(it->input) == it->expected);
|
||||||
|
}
|
||||||
|
|
||||||
CHECK(ret == it->second);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TEST_CASE("base58::is_base58 [char]") {
|
TEST_CASE("base58::is_base58 [char]") {
|
||||||
std::string valid_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
std::string valid_alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
std::string invalid_alphabet = "0OIl";
|
std::string invalid_alphabet = "0OIl";
|
||||||
|
|
||||||
for(int i = 0; i < valid_alphabet.length(); i++) {
|
|
||||||
char ch = valid_alphabet[i];
|
|
||||||
|
|
||||||
CHECK(libeosio::is_base58(ch) == true);
|
SUBCASE("valid") {
|
||||||
|
|
||||||
|
for(int i = 0; i < valid_alphabet.length(); i++) {
|
||||||
|
char ch = valid_alphabet[i];
|
||||||
|
|
||||||
|
CHECK(libeosio::is_base58(ch));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < invalid_alphabet.length(); i++) {
|
SUBCASE("invalid") {
|
||||||
char ch = invalid_alphabet[i];
|
for(int i = 0; i < invalid_alphabet.length(); i++) {
|
||||||
|
char ch = invalid_alphabet[i];
|
||||||
|
|
||||||
CHECK(libeosio::is_base58(ch) == false);
|
CHECK_FALSE(libeosio::is_base58(ch));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue