forked from ethereum/solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBytesUtilsTests.cpp
81 lines (67 loc) · 1.98 KB
/
BytesUtilsTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
#include <boost/test/unit_test.hpp>
#include <test/libsolidity/util/BytesUtils.h>
#include <libsolutil/CommonData.h>
using namespace solidity::util;
using namespace solidity::test;
namespace solidity::frontend::test
{
BOOST_AUTO_TEST_SUITE(BytesUtilsTest)
BOOST_AUTO_TEST_CASE(format_fixed)
{
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{0}), true, 2),
"0.00"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{1}), true, 2),
"0.01"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{123}), true, 2),
"1.23"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-1}), true, 2),
"-0.01"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-12}), true, 2),
"-0.12"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-123}), true, 2),
"-1.23"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-1234}), true, 2),
"-12.34"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-12345}), true, 2),
"-123.45"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-123456}), true, 2),
"-1234.56"
);
BOOST_CHECK_EQUAL(
BytesUtils::formatFixedPoint(toBigEndian(u256{-1234567}), true, 2),
"-12345.67"
);
}
BOOST_AUTO_TEST_SUITE_END()
}