Changeset View
Changeset View
Standalone View
Standalone View
src/test/uint256_tests.cpp
Show First 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(basics) { | ||||
BOOST_CHECK(uint160S("") == ZeroS); | BOOST_CHECK(uint160S("") == ZeroS); | ||||
BOOST_CHECK(R1S == uint160S(R1ArrayHex)); | BOOST_CHECK(R1S == uint160S(R1ArrayHex)); | ||||
BOOST_CHECK(uint160(R1S) == R1S); | BOOST_CHECK(uint160(R1S) == R1S); | ||||
BOOST_CHECK(uint160(ZeroS) == ZeroS); | BOOST_CHECK(uint160(ZeroS) == ZeroS); | ||||
BOOST_CHECK(uint160(OneS) == OneS); | BOOST_CHECK(uint160(OneS) == OneS); | ||||
} | } | ||||
static void CheckComparison(const uint256 &a, const uint256 &b) { | |||||
BOOST_CHECK(a < b); | |||||
BOOST_CHECK(b > a); | |||||
} | |||||
static void CheckComparison(const uint160 &a, const uint160 &b) { | |||||
BOOST_CHECK(a < b); | |||||
BOOST_CHECK(b > a); | |||||
} | |||||
// <= >= < > | // <= >= < > | ||||
BOOST_AUTO_TEST_CASE(comparison) { | BOOST_AUTO_TEST_CASE(comparison) { | ||||
uint256 LastL; | uint256 LastL; | ||||
for (int i = 255; i >= 0; --i) { | for (int i = 255; i >= 0; --i) { | ||||
uint256 TmpL; | uint256 TmpL; | ||||
*(TmpL.begin() + (i >> 3)) |= 1 << (7 - (i & 7)); | *(TmpL.begin() + (i >> 3)) |= 1 << (7 - (i & 7)); | ||||
BOOST_CHECK(LastL < TmpL); | CheckComparison(LastL, TmpL); | ||||
LastL = TmpL; | LastL = TmpL; | ||||
} | } | ||||
BOOST_CHECK(ZeroL < R1L); | CheckComparison(ZeroL, R1L); | ||||
BOOST_CHECK(R2L < R1L); | CheckComparison(R2L, R1L); | ||||
BOOST_CHECK(ZeroL < OneL); | CheckComparison(ZeroL, OneL); | ||||
BOOST_CHECK(OneL < MaxL); | CheckComparison(OneL, MaxL); | ||||
BOOST_CHECK(R1L < MaxL); | CheckComparison(R1L, MaxL); | ||||
BOOST_CHECK(R2L < MaxL); | CheckComparison(R2L, MaxL); | ||||
uint160 LastS; | uint160 LastS; | ||||
for (int i = 159; i >= 0; --i) { | for (int i = 159; i >= 0; --i) { | ||||
uint160 TmpS; | uint160 TmpS; | ||||
*(TmpS.begin() + (i >> 3)) |= 1 << (7 - (i & 7)); | *(TmpS.begin() + (i >> 3)) |= 1 << (7 - (i & 7)); | ||||
BOOST_CHECK(LastS < TmpS); | CheckComparison(LastS, TmpS); | ||||
LastS = TmpS; | LastS = TmpS; | ||||
} | } | ||||
BOOST_CHECK(ZeroS < R1S); | |||||
BOOST_CHECK(R2S < R1S); | CheckComparison(ZeroS, R1S); | ||||
BOOST_CHECK(ZeroS < OneS); | CheckComparison(R2S, R1S); | ||||
BOOST_CHECK(OneS < MaxS); | CheckComparison(ZeroS, OneS); | ||||
BOOST_CHECK(R1S < MaxS); | CheckComparison(OneS, MaxS); | ||||
BOOST_CHECK(R2S < MaxS); | CheckComparison(R1S, MaxS); | ||||
CheckComparison(R2S, MaxS); | |||||
} | } | ||||
// GetHex SetHex begin() end() size() GetLow64 GetSerializeSize, Serialize, | // GetHex SetHex begin() end() size() GetLow64 GetSerializeSize, Serialize, | ||||
// Unserialize | // Unserialize | ||||
BOOST_AUTO_TEST_CASE(methods) { | BOOST_AUTO_TEST_CASE(methods) { | ||||
BOOST_CHECK(R1L.GetHex() == R1L.ToString()); | BOOST_CHECK(R1L.GetHex() == R1L.ToString()); | ||||
BOOST_CHECK(R2L.GetHex() == R2L.ToString()); | BOOST_CHECK(R2L.GetHex() == R2L.ToString()); | ||||
BOOST_CHECK(OneL.GetHex() == OneL.ToString()); | BOOST_CHECK(OneL.GetHex() == OneL.ToString()); | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |