Line data Source code
1 : // Copyright (c) 2016-2020 The ZCash developers
2 : // Copyright (c) 2020 The PIVX Core 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/sapling_util.h"
9 : #include <boost/test/unit_test.hpp>
10 :
11 :
12 : BOOST_FIXTURE_TEST_SUITE(sapling_utils_tests, BasicTestingSetup)
13 :
14 2 : BOOST_AUTO_TEST_CASE(saplingConvertBytesVectorToVector) {
15 1 : std::vector<unsigned char> bytes = {0x00, 0x01, 0x03, 0x12, 0xFF};
16 1 : 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 2 : };
28 2 : BOOST_CHECK(convertBytesVectorToVector(bytes) == expected_bits);
29 1 : }
30 :
31 2 : BOOST_AUTO_TEST_CASE(saplingConvertVectorToInt) {
32 :
33 2 : BOOST_CHECK(convertVectorToInt({0}) == 0);
34 2 : BOOST_CHECK(convertVectorToInt({1}) == 1);
35 2 : BOOST_CHECK(convertVectorToInt({0,1}) == 1);
36 2 : BOOST_CHECK(convertVectorToInt({1,0}) == 2);
37 2 : BOOST_CHECK(convertVectorToInt({1,1}) == 3);
38 2 : BOOST_CHECK(convertVectorToInt({1,0,0}) == 4);
39 2 : BOOST_CHECK(convertVectorToInt({1,0,1}) == 5);
40 2 : BOOST_CHECK(convertVectorToInt({1,1,0}) == 6);
41 :
42 3 : BOOST_CHECK_THROW(convertVectorToInt(std::vector<bool>(100)), std::length_error);
43 :
44 1 : {
45 1 : std::vector<bool> v(63, 1);
46 2 : BOOST_CHECK(convertVectorToInt(v) == 0x7fffffffffffffff);
47 : }
48 :
49 1 : {
50 1 : std::vector<bool> v(64, 1);
51 2 : BOOST_CHECK(convertVectorToInt(v) == 0xffffffffffffffff);
52 : }
53 :
54 1 : }
55 :
56 : BOOST_AUTO_TEST_SUITE_END()
|