Test conversion between solution indices and minimal representation

This commit is contained in:
Jack Grigg 2016-08-24 13:42:52 +12:00
parent e273f05d10
commit 90b740fd3b
1 changed files with 26 additions and 0 deletions

View File

@ -40,6 +40,32 @@ TEST(equihash_tests, expand_and_contract_arrays) {
ParseHex("000007ff000007ff000007ff000007ff000007ff000007ff000007ff000007ff"));
}
void TestMinimalSolnRepr(const std::string &scope, size_t cBitLen,
std::vector<eh_index> indices,
std::vector<unsigned char> minimal)
{
SCOPED_TRACE(scope);
EXPECT_EQ(indices, GetIndicesFromMinimal(minimal, cBitLen));
EXPECT_EQ(minimal, GetMinimalFromIndices(indices, cBitLen));
}
TEST(equihash_tests, minimal_solution_representation) {
TestMinimalSolnRepr("Test 1", 20,
{1, 1, 1, 1, 1, 1, 1, 1},
ParseHex("000008000040000200001000008000040000200001"));
TestMinimalSolnRepr("Test 2", 20,
{2097151, 2097151, 2097151, 2097151,
2097151, 2097151, 2097151, 2097151},
ParseHex("ffffffffffffffffffffffffffffffffffffffffff"));
TestMinimalSolnRepr("Test 3", 20,
{131071, 128, 131071, 128, 131071, 128, 131071, 128},
ParseHex("0ffff8002003fffe000800ffff8002003fffe00080"));
TestMinimalSolnRepr("Test 4", 20,
{68, 41, 2097151, 1233, 665, 1023, 1, 1048575},
ParseHex("000220000a7ffffe004d10014c800ffc00002fffff"));
}
TEST(equihash_tests, is_probably_duplicate) {
std::shared_ptr<eh_trunc> p1 (new eh_trunc[4] {0, 1, 2, 3});
std::shared_ptr<eh_trunc> p2 (new eh_trunc[4] {0, 1, 1, 3});