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");
72 STNumber const factor{sfNumber, 100};
73 auto const iouValue = strikePrice.
iou();
74 IOUAmount const totalValue{iouValue * factor};
76 BEAST_EXPECT(totalAmount ==
Number{10'000});
112 auto const parseNumber = [](
std::string const& boundary) {
115 auto const expectParseThrows = [
this, &parseNumber](
std::string const& boundary) {
118 parseNumber(boundary);
128 auto constexpr positiveBoundary =
"922337203685477580";
129 auto constexpr negativeBoundary =
"-922337203685477580";
132 expectParseThrows(positiveBoundary);
133 expectParseThrows(negativeBoundary);
138 parseNumber(positiveBoundary) ==
141 parseNumber(negativeBoundary) ==
154 expectParseThrows(maxInt);
155 expectParseThrows(minInt);
161 parseNumber(maxInt) ==
164 expectParseThrows(minInt);
186 auto const expectJsonThrows = [
this](
196 out <<
"Json: " << num.
asString() <<
" got exception: " << e.
what()
197 <<
", expected: " << expected;
203 expectJsonThrows(
"1e2000000",
"Number::normalize 2");
204 expectJsonThrows(
"1e2000000000",
"Number::normalize 2");
207 expectJsonThrows(
"",
"'' is not a number");
208 expectJsonThrows(
"e",
"'e' is not a number");
209 expectJsonThrows(
"1e",
"'1e' is not a number");
210 expectJsonThrows(
"e2",
"'e2' is not a number");
217 "1234567890123456789012345678901234567890123456789012345678"
218 "9012345678901234567890123456789012345678901234567890123456"
219 "78901234567890123456789012345678901234567890");
235 std::string const expected =
"'001' is not a number";
236 BEAST_EXPECT(e.
what() == expected);
246 std::string const expected =
"'000.0' is not a number";
247 BEAST_EXPECT(e.
what() == expected);
258 std::string const expected =
"'.1' is not a number";
259 BEAST_EXPECT(e.
what() == expected);
269 std::string const expected =
"'1.' is not a number";
270 BEAST_EXPECT(e.
what() == expected);
280 std::string const expected =
"'1.e3' is not a number";
281 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.