xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
libxrpl
shamap
SHAMapAddNode.cpp
1
#include <xrpl/shamap/SHAMapAddNode.h>
2
3
#include <gtest/gtest.h>
4
5
namespace
xrpl::tests
{
6
7
// get() is a log format, so its wording is pinned here, once. Every other site reads the same tally
8
// by value, through the count and verdict accessors.
9
TEST
(
SHAMapAddNode
, get_names_every_non_empty_count)
10
{
11
EXPECT_EQ(
SHAMapAddNode
{}.
get
(),
"no nodes processed"
);
12
EXPECT_EQ(
SHAMapAddNode::useful
().
get
(),
"good:1"
);
13
EXPECT_EQ(
SHAMapAddNode::invalid
().
get
(),
"bad:1"
);
14
EXPECT_EQ(
SHAMapAddNode::duplicate
().
get
(),
"dupe:1"
);
15
16
// Several of a kind are counted, and the counts are joined in a fixed order with a single
17
// space, whichever order they were recorded in.
18
SHAMapAddNode
san;
19
san.
incInvalid
();
20
san.
incUseful
();
21
san.
incUseful
();
22
san.
incDuplicate
();
23
EXPECT_EQ(san.
get
(),
"good:2 bad:1 dupe:1"
);
24
25
san.
reset
();
26
EXPECT_EQ(san.
get
(),
"no nodes processed"
);
27
}
28
29
// The three counts and the verdicts derived from them.
30
TEST
(
SHAMapAddNode
, counts_and_verdicts_agree)
31
{
32
SHAMapAddNode
san;
33
EXPECT_EQ(san.
getGood
(), 0);
34
EXPECT_EQ(san.
getBad
(), 0);
35
EXPECT_EQ(san.
getDuplicate
(), 0);
36
EXPECT_FALSE(san.
isInvalid
());
37
EXPECT_FALSE(san.
isUseful
());
38
39
// Good counts what produced a good result, and useful is that count being non-zero.
40
san.
incUseful
();
41
EXPECT_EQ(san.
getGood
(), 1);
42
EXPECT_TRUE(san.
isUseful
());
43
EXPECT_TRUE(san.
isGood
());
44
45
// A duplicate counts toward good. isUseful() here reflects the incUseful() above.
46
san.
incDuplicate
();
47
EXPECT_EQ(san.
getDuplicate
(), 1);
48
EXPECT_FALSE(san.
isInvalid
());
49
EXPECT_TRUE(san.
isGood
());
50
51
// Bad is a count, so a batch that carries on past a rejected node reports one per node, which
52
// distinguishes "stopped on the first" from "rejected several".
53
san.
incInvalid
();
54
EXPECT_EQ(san.
getBad
(), 1);
55
EXPECT_TRUE(san.
isInvalid
());
56
EXPECT_TRUE(san.
isGood
()) <<
"one bad node among two accepted ones is still a good batch"
;
57
58
san.
incInvalid
();
59
san.
incInvalid
();
60
EXPECT_EQ(san.
getGood
(), 1);
61
EXPECT_EQ(san.
getBad
(), 3);
62
EXPECT_EQ(san.
getDuplicate
(), 1);
63
EXPECT_FALSE(san.
isGood
()) <<
"more bad nodes than accepted ones is not a good batch"
;
64
65
// Adding one verdict to another sums every count.
66
SHAMapAddNode
total;
67
total +=
SHAMapAddNode::useful
();
68
total +=
SHAMapAddNode::invalid
();
69
total +=
SHAMapAddNode::invalid
();
70
total +=
SHAMapAddNode::duplicate
();
71
EXPECT_EQ(total.
getGood
(), 1);
72
EXPECT_EQ(total.
getBad
(), 2);
73
EXPECT_EQ(total.
getDuplicate
(), 1);
74
}
75
76
}
// namespace xrpl::tests
xrpl::SHAMapAddNode
Definition
SHAMapAddNode.h:9
xrpl::SHAMapAddNode::getBad
int getBad() const
Definition
SHAMapAddNode.h:161
xrpl::SHAMapAddNode::getGood
int getGood() const
Definition
SHAMapAddNode.h:155
xrpl::SHAMapAddNode::incDuplicate
void incDuplicate()
Record one node that was not needed: the map already held it, or the map or its acquisition was no lo...
Definition
SHAMapAddNode.h:149
xrpl::SHAMapAddNode::reset
void reset()
Clear every count back to zero.
Definition
SHAMapAddNode.h:209
xrpl::SHAMapAddNode::getDuplicate
int getDuplicate() const
Definition
SHAMapAddNode.h:167
xrpl::SHAMapAddNode::incUseful
void incUseful()
Record one node that produced a good result.
Definition
SHAMapAddNode.h:143
xrpl::SHAMapAddNode::duplicate
static SHAMapAddNode duplicate()
Definition
SHAMapAddNode.h:191
xrpl::SHAMapAddNode::useful
static SHAMapAddNode useful()
Definition
SHAMapAddNode.h:197
xrpl::SHAMapAddNode::isInvalid
bool isInvalid() const
Definition
SHAMapAddNode.h:179
xrpl::SHAMapAddNode::isGood
bool isGood() const
Whether nodes that produced a good result or were not needed outnumber the ones rejected.
Definition
SHAMapAddNode.h:173
xrpl::SHAMapAddNode::get
std::string get() const
Render the tally as a log line.
Definition
SHAMapAddNode.h:215
xrpl::SHAMapAddNode::incInvalid
void incInvalid()
Record one node that was rejected.
Definition
SHAMapAddNode.h:137
xrpl::SHAMapAddNode::invalid
static SHAMapAddNode invalid()
Definition
SHAMapAddNode.h:203
xrpl::SHAMapAddNode::isUseful
bool isUseful() const
Definition
SHAMapAddNode.h:185
xrpl::tests
Definition
LedgerNodeHelpers_test.cpp:21
xrpl::tests::TEST
TEST(IntrusiveSharedTest, ref_counts_on_a_bare_object)
Definition
IntrusiveShared.cpp:193
xrpl::get
T get(Section const §ion, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Definition
BasicConfig.h:360
Generated by
1.17.0