Changeset View
Changeset View
Standalone View
Standalone View
src/test/compress_tests.cpp
Show All 36 Lines | |||||
static bool TestPair(uint64_t dec, uint64_t enc) { | static bool TestPair(uint64_t dec, uint64_t enc) { | ||||
return CTxOutCompressor::CompressAmount(dec) == enc && | return CTxOutCompressor::CompressAmount(dec) == enc && | ||||
CTxOutCompressor::DecompressAmount(enc) == dec; | CTxOutCompressor::DecompressAmount(enc) == dec; | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(compress_amounts) { | BOOST_AUTO_TEST_CASE(compress_amounts) { | ||||
BOOST_CHECK(TestPair(0, 0x0)); | BOOST_CHECK(TestPair(0, 0x0)); | ||||
BOOST_CHECK(TestPair(1, 0x1)); | BOOST_CHECK(TestPair(1, 0x1)); | ||||
BOOST_CHECK(TestPair(CENT, 0x7)); | BOOST_CHECK(TestPair(CENT.GetSatoshis(), 0x7)); | ||||
BOOST_CHECK(TestPair(COIN, 0x9)); | BOOST_CHECK(TestPair(COIN.GetSatoshis(), 0x9)); | ||||
BOOST_CHECK(TestPair(50 * COIN, 0x32)); | BOOST_CHECK(TestPair(50 * COIN.GetSatoshis(), 0x32)); | ||||
BOOST_CHECK(TestPair(21000000 * COIN, 0x1406f40)); | BOOST_CHECK(TestPair(21000000 * COIN.GetSatoshis(), 0x1406f40)); | ||||
for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++) { | for (uint64_t i = 1; i <= NUM_MULTIPLES_UNIT; i++) { | ||||
BOOST_CHECK(TestEncode(i)); | BOOST_CHECK(TestEncode(i)); | ||||
} | } | ||||
for (uint64_t i = 1; i <= NUM_MULTIPLES_CENT; i++) { | for (uint64_t i = 1; i <= NUM_MULTIPLES_CENT; i++) { | ||||
BOOST_CHECK(TestEncode(i * CENT)); | BOOST_CHECK(TestEncode(i * CENT.GetSatoshis())); | ||||
} | } | ||||
for (uint64_t i = 1; i <= NUM_MULTIPLES_1BCC; i++) { | for (uint64_t i = 1; i <= NUM_MULTIPLES_1BCC; i++) { | ||||
BOOST_CHECK(TestEncode(i * COIN)); | BOOST_CHECK(TestEncode(i * COIN.GetSatoshis())); | ||||
} | } | ||||
for (uint64_t i = 1; i <= NUM_MULTIPLES_50BCC; i++) { | for (uint64_t i = 1; i <= NUM_MULTIPLES_50BCC; i++) { | ||||
BOOST_CHECK(TestEncode(i * 50 * COIN)); | BOOST_CHECK(TestEncode(i * 50 * COIN.GetSatoshis())); | ||||
} | } | ||||
for (uint64_t i = 0; i < 100000; i++) { | for (uint64_t i = 0; i < 100000; i++) { | ||||
BOOST_CHECK(TestDecode(i)); | BOOST_CHECK(TestDecode(i)); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |