Extend byte array expansion and compression methods with optional padding
This commit is contained in:
@@ -4,31 +4,37 @@
|
||||
#include "crypto/equihash.h"
|
||||
#include "uint256.h"
|
||||
|
||||
void TestExpandAndCompress(const std::string &scope, size_t bit_len,
|
||||
void TestExpandAndCompress(const std::string &scope, size_t bit_len, size_t byte_pad,
|
||||
std::vector<unsigned char> compact,
|
||||
std::vector<unsigned char> expanded)
|
||||
{
|
||||
SCOPED_TRACE(scope);
|
||||
|
||||
std::vector<unsigned char> out(expanded.size());
|
||||
ExpandArray(compact.data(), compact.size(), out.data(), out.size(), bit_len);
|
||||
ExpandArray(compact.data(), compact.size(),
|
||||
out.data(), out.size(), bit_len, byte_pad);
|
||||
EXPECT_EQ(expanded, out);
|
||||
|
||||
out.resize(compact.size());
|
||||
CompressArray(expanded.data(), expanded.size(), out.data(), out.size(), bit_len);
|
||||
CompressArray(expanded.data(), expanded.size(),
|
||||
out.data(), out.size(), bit_len, byte_pad);
|
||||
EXPECT_EQ(compact, out);
|
||||
}
|
||||
|
||||
TEST(equihash_tests, expand_and_contract_arrays) {
|
||||
TestExpandAndCompress("8 11-bit chunks, all-ones", 11,
|
||||
TestExpandAndCompress("8 11-bit chunks, all-ones", 11, 0,
|
||||
ParseHex("ffffffffffffffffffffff"),
|
||||
ParseHex("07ff07ff07ff07ff07ff07ff07ff07ff"));
|
||||
TestExpandAndCompress("8 21-bit chunks, alternating 1s and 0s", 21,
|
||||
TestExpandAndCompress("8 21-bit chunks, alternating 1s and 0s", 21, 0,
|
||||
ParseHex("aaaaad55556aaaab55555aaaaad55556aaaab55555"),
|
||||
ParseHex("155555155555155555155555155555155555155555155555"));
|
||||
TestExpandAndCompress("16 14-bit chunks, alternating 11s and 00s", 14,
|
||||
TestExpandAndCompress("16 14-bit chunks, alternating 11s and 00s", 14, 0,
|
||||
ParseHex("cccf333cccf333cccf333cccf333cccf333cccf333cccf333cccf333"),
|
||||
ParseHex("3333333333333333333333333333333333333333333333333333333333333333"));
|
||||
|
||||
TestExpandAndCompress("8 11-bit chunks, all-ones, 2-byte padding", 11, 2,
|
||||
ParseHex("ffffffffffffffffffffff"),
|
||||
ParseHex("000007ff000007ff000007ff000007ff000007ff000007ff000007ff000007ff"));
|
||||
}
|
||||
|
||||
TEST(equihash_tests, is_probably_duplicate) {
|
||||
|
||||
Reference in New Issue
Block a user