]> Git Repo - VerusCoin.git/blob - src/test/compress_tests.cpp
print the caught error instead of raising an error
[VerusCoin.git] / src / test / compress_tests.cpp
1 // Copyright (c) 2012-2013 The Bitcoin Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #include "compressor.h"
6 #include "util.h"
7
8 #include <stdint.h>
9
10 #include <boost/test/unit_test.hpp>
11
12 // amounts 0.00000001 .. 0.00100000
13 #define NUM_MULTIPLES_UNIT 100000
14
15 // amounts 0.01 .. 100.00
16 #define NUM_MULTIPLES_CENT 10000
17
18 // amounts 1 .. 10000
19 #define NUM_MULTIPLES_1BTC 10000
20
21 // amounts 50 .. 21000000
22 #define NUM_MULTIPLES_50BTC 420000
23
24 BOOST_AUTO_TEST_SUITE(compress_tests)
25
26 bool static TestEncode(uint64_t in) {
27     return in == CTxOutCompressor::DecompressAmount(CTxOutCompressor::CompressAmount(in));
28 }
29
30 bool static TestDecode(uint64_t in) {
31     return in == CTxOutCompressor::CompressAmount(CTxOutCompressor::DecompressAmount(in));
32 }
33
34 bool static TestPair(uint64_t dec, uint64_t enc) {
35     return CTxOutCompressor::CompressAmount(dec) == enc &&
36            CTxOutCompressor::DecompressAmount(enc) == dec;
37 }
38
39 BOOST_AUTO_TEST_CASE(compress_amounts)
40 {
41     BOOST_CHECK(TestPair(            0,       0x0));
42     BOOST_CHECK(TestPair(            1,       0x1));
43     BOOST_CHECK(TestPair(         CENT,       0x7));
44     BOOST_CHECK(TestPair(         COIN,       0x9));
45     BOOST_CHECK(TestPair(      50*COIN,      0x32));
46     BOOST_CHECK(TestPair(21000000*COIN, 0x1406f40));
47
48     for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++)
49         BOOST_CHECK(TestEncode(i));
50
51     for (uint64_t i = 1; i <= NUM_MULTIPLES_CENT; i++)
52         BOOST_CHECK(TestEncode(i * CENT));
53
54     for (uint64_t i = 1; i <= NUM_MULTIPLES_1BTC; i++)
55         BOOST_CHECK(TestEncode(i * COIN));
56
57     for (uint64_t i = 1; i <= NUM_MULTIPLES_50BTC; i++)
58         BOOST_CHECK(TestEncode(i * 50 * COIN));
59
60     for (uint64_t i = 0; i < 100000; i++)
61         BOOST_CHECK(TestDecode(i));
62 }
63
64 BOOST_AUTO_TEST_SUITE_END()
This page took 0.027025 seconds and 4 git commands to generate.