1 #include <gtest/gtest.h>
2 #include "zcash/util.h"
4 TEST(libzcash_utils, convertBytesVectorToVector)
6 std::vector<unsigned char> bytes = {0x00, 0x01, 0x03, 0x12, 0xFF};
7 std::vector<bool> expected_bits = {
9 0, 0, 0, 0, 0, 0, 0, 0,
11 0, 0, 0, 0, 0, 0, 0, 1,
13 0, 0, 0, 0, 0, 0, 1, 1,
15 0, 0, 0, 1, 0, 0, 1, 0,
17 1, 1, 1, 1, 1, 1, 1, 1
19 ASSERT_TRUE(convertBytesVectorToVector(bytes) == expected_bits);
22 TEST(libzcash_utils, convertVectorToInt)
24 ASSERT_TRUE(convertVectorToInt({0}) == 0);
25 ASSERT_TRUE(convertVectorToInt({1}) == 1);
26 ASSERT_TRUE(convertVectorToInt({0,1}) == 1);
27 ASSERT_TRUE(convertVectorToInt({1,0}) == 2);
28 ASSERT_TRUE(convertVectorToInt({1,1}) == 3);
29 ASSERT_TRUE(convertVectorToInt({1,0,0}) == 4);
30 ASSERT_TRUE(convertVectorToInt({1,0,1}) == 5);
31 ASSERT_TRUE(convertVectorToInt({1,1,0}) == 6);
33 ASSERT_THROW(convertVectorToInt(std::vector<bool>(100)), std::length_error);
36 std::vector<bool> v(63, 1);
37 ASSERT_TRUE(convertVectorToInt(v) == 0x7fffffffffffffff);
41 std::vector<bool> v(64, 1);
42 ASSERT_TRUE(convertVectorToInt(v) == 0xffffffffffffffff);