|
| 1 | +// Copyright (c) 2016-2020 The ZCash developers |
| 2 | +// Copyright (c) 2020 The PIVX developers |
| 3 | +// Distributed under the MIT software license, see the accompanying |
| 4 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | + |
| 6 | +#include "test/test_pivx.h" |
| 7 | + |
| 8 | +#include "sapling/util.h" |
| 9 | +#include <boost/test/unit_test.hpp> |
| 10 | + |
| 11 | + |
| 12 | +BOOST_FIXTURE_TEST_SUITE(sapling_utils_tests, BasicTestingSetup) |
| 13 | + |
| 14 | +BOOST_AUTO_TEST_CASE(saplingConvertBytesVectorToVector) { |
| 15 | + std::vector<unsigned char> bytes = {0x00, 0x01, 0x03, 0x12, 0xFF}; |
| 16 | + std::vector<bool> expected_bits = { |
| 17 | + // 0x00 |
| 18 | + 0, 0, 0, 0, 0, 0, 0, 0, |
| 19 | + // 0x01 |
| 20 | + 0, 0, 0, 0, 0, 0, 0, 1, |
| 21 | + // 0x03 |
| 22 | + 0, 0, 0, 0, 0, 0, 1, 1, |
| 23 | + // 0x12 |
| 24 | + 0, 0, 0, 1, 0, 0, 1, 0, |
| 25 | + // 0xFF |
| 26 | + 1, 1, 1, 1, 1, 1, 1, 1 |
| 27 | + }; |
| 28 | + BOOST_CHECK(convertBytesVectorToVector(bytes) == expected_bits); |
| 29 | +} |
| 30 | + |
| 31 | +BOOST_AUTO_TEST_CASE(saplingConvertVectorToInt) { |
| 32 | + |
| 33 | + BOOST_CHECK(convertVectorToInt({0}) == 0); |
| 34 | + BOOST_CHECK(convertVectorToInt({1}) == 1); |
| 35 | + BOOST_CHECK(convertVectorToInt({0,1}) == 1); |
| 36 | + BOOST_CHECK(convertVectorToInt({1,0}) == 2); |
| 37 | + BOOST_CHECK(convertVectorToInt({1,1}) == 3); |
| 38 | + BOOST_CHECK(convertVectorToInt({1,0,0}) == 4); |
| 39 | + BOOST_CHECK(convertVectorToInt({1,0,1}) == 5); |
| 40 | + BOOST_CHECK(convertVectorToInt({1,1,0}) == 6); |
| 41 | + |
| 42 | + BOOST_CHECK_THROW(convertVectorToInt(std::vector<bool>(100)), std::length_error); |
| 43 | + |
| 44 | + { |
| 45 | + std::vector<bool> v(63, 1); |
| 46 | + BOOST_CHECK(convertVectorToInt(v) == 0x7fffffffffffffff); |
| 47 | + } |
| 48 | + |
| 49 | + { |
| 50 | + std::vector<bool> v(64, 1); |
| 51 | + BOOST_CHECK(convertVectorToInt(v) == 0xffffffffffffffff); |
| 52 | + } |
| 53 | + |
| 54 | +} |
| 55 | + |
| 56 | +BOOST_AUTO_TEST_SUITE_END() |
0 commit comments