1#include <xrpl/basics/Number.h>
2#include <xrpl/beast/unit_test/suite.h>
3#include <xrpl/json/json_forwards.h>
4#include <xrpl/protocol/IOUAmount.h>
5#include <xrpl/protocol/Issue.h>
6#include <xrpl/protocol/SField.h>
7#include <xrpl/protocol/STAmount.h>
8#include <xrpl/protocol/STNumber.h>
9#include <xrpl/protocol/Serializer.h>
28 STNumber const before{sfNumber, number};
29 BEAST_EXPECT(number == before);
32 BEAST_EXPECT(s.
size() == 12);
35 BEAST_EXPECT(
after.isEquivalent(before));
36 BEAST_EXPECT(number ==
after);
44 BEAST_EXPECT(stnum.
getSType() == STI_NUMBER);
45 BEAST_EXPECT(stnum.
getText() ==
"0");
66 STNumber const factor{sfNumber, 100};
67 auto const iouValue = strikePrice.
iou();
68 IOUAmount const totalValue{iouValue * factor};
70 BEAST_EXPECT(totalAmount ==
Number{10'000});
106 auto const parseNumber = [](
std::string const& boundary) {
109 auto const expectParseThrows = [
this, &parseNumber](
std::string const& boundary) {
112 parseNumber(boundary);
122 auto constexpr positiveBoundary =
"922337203685477580";
123 auto constexpr negativeBoundary =
"-922337203685477580";
126 expectParseThrows(positiveBoundary);
127 expectParseThrows(negativeBoundary);
132 parseNumber(positiveBoundary) ==
135 parseNumber(negativeBoundary) ==
148 expectParseThrows(maxInt);
149 expectParseThrows(minInt);
155 parseNumber(maxInt) ==
158 expectParseThrows(minInt);
180 auto const expectJsonThrows = [
this](
190 out <<
"Json: " << num.
asString() <<
" got exception: " << e.
what()
191 <<
", expected: " << expected;
197 expectJsonThrows(
"1e2000000",
"Number::normalize 2");
198 expectJsonThrows(
"1e2000000000",
"Number::normalize 2");
201 expectJsonThrows(
"",
"'' is not a number");
202 expectJsonThrows(
"e",
"'e' is not a number");
203 expectJsonThrows(
"1e",
"'1e' is not a number");
204 expectJsonThrows(
"e2",
"'e2' is not a number");
211 "1234567890123456789012345678901234567890123456789012345678"
212 "9012345678901234567890123456789012345678901234567890123456"
213 "78901234567890123456789012345678901234567890");
229 std::string const expected =
"'001' is not a number";
230 BEAST_EXPECT(e.
what() == expected);
240 std::string const expected =
"'000.0' is not a number";
241 BEAST_EXPECT(e.
what() == expected);
252 std::string const expected =
"'.1' is not a number";
253 BEAST_EXPECT(e.
what() == expected);
263 std::string const expected =
"'1.' is not a number";
264 BEAST_EXPECT(e.
what() == expected);
274 std::string const expected =
"'1.e3' is not a number";
275 BEAST_EXPECT(e.
what() == expected);
void fail(String const &reason, char const *file, int line)
Record a failure.
TestcaseT testcase
Memberspace for declaring test cases.
std::string asString() const
Returns the unquoted string value.
Floating point representation of amounts with high dynamic range.
A currency issued by an account.
Sets the new scale and restores the old scale when it leaves scope.
Number is a floating point type that can represent a wide range of values.
static constexpr int kMinExponent
static MantissaRange::MantissaScale getMantissaScale()
Returns which mantissa scale is currently in use for normalization.
static constexpr int kMaxExponent
constexpr TIss const & get() const
void add(Serializer &s) const override
bool isDefault() const override
std::string getText() const override
SerializedTypeID getSType() const override
Number const & value() const
Slice slice() const noexcept
std::size_t size() const noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
int scale(Number const &number, Asset const &asset)
Get the scale of a Number for a given asset.
std::string to_string(BaseUInt< Bits, Tag > const &a)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
STNumber numberFromJson(SField const &field, json::Value const &value)
Issue const & noIssue()
Returns an asset specifier that represents no account and currency.
BEAST_DEFINE_TESTSUITE(AccountTxPaging, app, xrpl)
static std::set< MantissaScale > const & getAllScales()
void testCombo(Number number)
void run() override
Runs the suite.