mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 16:57:56 +00:00
Add prevMissing unit test to RangeSet
This commit is contained in:
@@ -251,7 +251,23 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void runTest ()
|
RangeSet createPredefinedSet ()
|
||||||
|
{
|
||||||
|
RangeSet set;
|
||||||
|
|
||||||
|
// Set will include:
|
||||||
|
// [ 0, 5]
|
||||||
|
// [10,15]
|
||||||
|
// [20,25]
|
||||||
|
// etc...
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; ++i)
|
||||||
|
set.setRange (10 * i, 10 * i + 5);
|
||||||
|
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testMembership ()
|
||||||
{
|
{
|
||||||
beginTest ("membership");
|
beginTest ("membership");
|
||||||
|
|
||||||
@@ -268,6 +284,30 @@ public:
|
|||||||
expect (!r1.hasValue (5));
|
expect (!r1.hasValue (5));
|
||||||
|
|
||||||
expect (r2.hasValue (9));
|
expect (r2.hasValue (9));
|
||||||
|
}
|
||||||
|
|
||||||
|
void testPrevMissing ()
|
||||||
|
{
|
||||||
|
beginTest ("prevMissing");
|
||||||
|
|
||||||
|
RangeSet const set = createPredefinedSet ();
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; ++i)
|
||||||
|
{
|
||||||
|
int const oneBelowRange = (10*(i/10))-1;
|
||||||
|
|
||||||
|
int const expectedPrevMissing =
|
||||||
|
((i % 10) > 6) ? (i-1) : oneBelowRange;
|
||||||
|
|
||||||
|
expect (set.prevMissing (i) == expectedPrevMissing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void runTest ()
|
||||||
|
{
|
||||||
|
testMembership ();
|
||||||
|
|
||||||
|
testPrevMissing ();
|
||||||
|
|
||||||
// TODO: Traverse functions must be tested
|
// TODO: Traverse functions must be tested
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,12 @@ public:
|
|||||||
// largest number not in the set that is less than the given number
|
// largest number not in the set that is less than the given number
|
||||||
uint32 prevMissing (uint32) const;
|
uint32 prevMissing (uint32) const;
|
||||||
|
|
||||||
|
// Add an item to the set
|
||||||
void setValue (uint32);
|
void setValue (uint32);
|
||||||
|
|
||||||
|
// Add the closed interval to the set
|
||||||
void setRange (uint32, uint32);
|
void setRange (uint32, uint32);
|
||||||
|
|
||||||
void clearValue (uint32);
|
void clearValue (uint32);
|
||||||
|
|
||||||
std::string toString () const;
|
std::string toString () const;
|
||||||
|
|||||||
Reference in New Issue
Block a user