mirror of
https://github.com/fastfloat/fast_float.git
synced 2025-12-06 16:56:57 +08:00
trying to fix tests.
This commit is contained in:
parent
bbf4193339
commit
2da25b51c8
@ -9,3 +9,4 @@ Jan Pharago
|
|||||||
Maya Warrier
|
Maya Warrier
|
||||||
Taha Khokhar
|
Taha Khokhar
|
||||||
Anders Dalvander
|
Anders Dalvander
|
||||||
|
Elle Solomina
|
||||||
|
|||||||
@ -7,9 +7,9 @@
|
|||||||
int main() {
|
int main() {
|
||||||
std::string const input = "3,1416 xyz ";
|
std::string const input = "3,1416 xyz ";
|
||||||
double result;
|
double result;
|
||||||
fast_float::parse_options options{fast_float::chars_format::general, ','};
|
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result, options);
|
input.data(), input.data() + input.size(), result,
|
||||||
|
fast_float::parse_options{fast_float::chars_format::general, ','});
|
||||||
if ((answer.ec != std::errc()) || ((result != 3.1416))) {
|
if ((answer.ec != std::errc()) || ((result != 3.1416))) {
|
||||||
std::cerr << "parsing failure\n";
|
std::cerr << "parsing failure\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
@ -9,11 +9,11 @@
|
|||||||
int main_readme() {
|
int main_readme() {
|
||||||
std::string const input = "1d+4";
|
std::string const input = "1d+4";
|
||||||
double result;
|
double result;
|
||||||
fast_float::parse_options options{
|
|
||||||
fast_float::chars_format::fortran |
|
|
||||||
fast_float::chars_format::allow_leading_plus};
|
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result, options);
|
input.data(), input.data() + input.size(), result,
|
||||||
|
fast_float::parse_options {
|
||||||
|
fast_float::chars_format::fortran |
|
||||||
|
fast_float::chars_format::allow_leading_plus});
|
||||||
if ((answer.ec != std::errc()) || ((result != 10000))) {
|
if ((answer.ec != std::errc()) || ((result != 10000))) {
|
||||||
std::cerr << "parsing failure\n" << result << "\n";
|
std::cerr << "parsing failure\n" << result << "\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -31,15 +31,15 @@ int main() {
|
|||||||
"1d-1", "1d-2", "1d-3", "1d-4"};
|
"1d-1", "1d-2", "1d-3", "1d-4"};
|
||||||
std::vector<std::string> const fmt3{"+1+4", "+1+3", "+1+2", "+1+1", "+1+0",
|
std::vector<std::string> const fmt3{"+1+4", "+1+3", "+1+2", "+1+1", "+1+0",
|
||||||
"+1-1", "+1-2", "+1-3", "+1-4"};
|
"+1-1", "+1-2", "+1-3", "+1-4"};
|
||||||
fast_float::parse_options const options{
|
|
||||||
fast_float::chars_format::fortran |
|
|
||||||
fast_float::chars_format::allow_leading_plus};
|
|
||||||
|
|
||||||
for (auto const &f : fmt1) {
|
for (auto const &f : fmt1) {
|
||||||
auto d{std::distance(&fmt1[0], &f)};
|
auto d{std::distance(&fmt1[0], &f)};
|
||||||
double result;
|
double result;
|
||||||
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
||||||
result, options)};
|
result,
|
||||||
|
fast_float::parse_options {
|
||||||
|
fast_float::chars_format::fortran |
|
||||||
|
fast_float::chars_format::allow_leading_plus})};
|
||||||
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
||||||
std::cerr << "parsing failure on " << f << std::endl;
|
std::cerr << "parsing failure on " << f << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -50,7 +50,10 @@ int main() {
|
|||||||
auto d{std::distance(&fmt2[0], &f)};
|
auto d{std::distance(&fmt2[0], &f)};
|
||||||
double result;
|
double result;
|
||||||
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
||||||
result, options)};
|
result,
|
||||||
|
fast_float::parse_options {
|
||||||
|
fast_float::chars_format::fortran |
|
||||||
|
fast_float::chars_format::allow_leading_plus})};
|
||||||
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
||||||
std::cerr << "parsing failure on " << f << std::endl;
|
std::cerr << "parsing failure on " << f << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -61,7 +64,10 @@ int main() {
|
|||||||
auto d{std::distance(&fmt3[0], &f)};
|
auto d{std::distance(&fmt3[0], &f)};
|
||||||
double result;
|
double result;
|
||||||
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
auto answer{fast_float::from_chars_advanced(f.data(), f.data() + f.size(),
|
||||||
result, options)};
|
result,
|
||||||
|
fast_float::parse_options {
|
||||||
|
fast_float::chars_format::fortran |
|
||||||
|
fast_float::chars_format::allow_leading_plus})};
|
||||||
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
if (answer.ec != std::errc() || result != expected[std::size_t(d)]) {
|
||||||
std::cerr << "parsing failure on " << f << std::endl;
|
std::cerr << "parsing failure on " << f << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
@ -7,11 +7,12 @@
|
|||||||
int main_readme() {
|
int main_readme() {
|
||||||
std::string const input = "+.1"; // not valid
|
std::string const input = "+.1"; // not valid
|
||||||
double result;
|
double result;
|
||||||
fast_float::parse_options options{
|
|
||||||
fast_float::chars_format::json |
|
|
||||||
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result, options);
|
input.data(), input.data() + input.size(), result,
|
||||||
|
fast_float::parse_options options{
|
||||||
|
fast_float::chars_format::json |
|
||||||
|
fast_float::chars_format::allow_leading_plus} // should be ignored
|
||||||
|
);
|
||||||
if (answer.ec == std::errc()) {
|
if (answer.ec == std::errc()) {
|
||||||
std::cerr << "should have failed\n";
|
std::cerr << "should have failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -22,11 +23,12 @@ int main_readme() {
|
|||||||
int main_readme2() {
|
int main_readme2() {
|
||||||
std::string const input = "inf"; // not valid in JSON
|
std::string const input = "inf"; // not valid in JSON
|
||||||
double result;
|
double result;
|
||||||
fast_float::parse_options options{
|
|
||||||
fast_float::chars_format::json |
|
|
||||||
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
|
||||||
auto answer = fast_float::from_chars_advanced(
|
auto answer = fast_float::from_chars_advanced(
|
||||||
input.data(), input.data() + input.size(), result, options);
|
input.data(), input.data() + input.size(), result,
|
||||||
|
fast_float::parse_options options{
|
||||||
|
fast_float::chars_format::json |
|
||||||
|
fast_float::chars_format::allow_leading_plus} // should be ignored
|
||||||
|
);
|
||||||
if (answer.ec == std::errc()) {
|
if (answer.ec == std::errc()) {
|
||||||
std::cerr << "should have failed\n";
|
std::cerr << "should have failed\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -38,11 +40,12 @@ int main_readme3() {
|
|||||||
std::string const input =
|
std::string const input =
|
||||||
"inf"; // not valid in JSON but we allow it with json_or_infnan
|
"inf"; // not valid in JSON but we allow it with json_or_infnan
|
||||||
double result;
|
double result;
|
||||||
fast_float::parse_options options{
|
auto answer = fast_float::from_chars_advanced(
|
||||||
|
input.data(), input.data() + input.size(), result,
|
||||||
|
fast_float::parse_options options{
|
||||||
fast_float::chars_format::json_or_infnan |
|
fast_float::chars_format::json_or_infnan |
|
||||||
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
fast_float::chars_format::allow_leading_plus}; // should be ignored
|
||||||
auto answer = fast_float::from_chars_advanced(
|
);
|
||||||
input.data(), input.data() + input.size(), result, options);
|
|
||||||
if (answer.ec != std::errc() || (!std::isinf(result))) {
|
if (answer.ec != std::errc() || (!std::isinf(result))) {
|
||||||
std::cerr << "should have parsed infinity\n";
|
std::cerr << "should have parsed infinity\n";
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user