Skip to content

Added basic tests for fast_int in fast_int.cpp#1

Merged
mayawarrier merged 10 commits intomayawarrier:mainfrom
marvinyywu:main
Dec 13, 2023
Merged

Added basic tests for fast_int in fast_int.cpp#1
mayawarrier merged 10 commits intomayawarrier:mainfrom
marvinyywu:main

Conversation

@marvinyywu
Copy link
Copy Markdown
Collaborator

No description provided.

@mayawarrier mayawarrier force-pushed the main branch 2 times, most recently from 0b48101 to 3d446f1 Compare December 12, 2023 06:56
Comment thread tests/fast_int.cpp Outdated
int result;
auto answer = fast_float::from_chars(f.data(), f.data() + f.size(), result, 100);
if (answer.ec != std::errc()) {
std::cerr << "could not convert to int for input: " << std::quoted(f) << std::endl;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid bases are always rejected with std::errc::invalid_argument, so this test will never succeed.

Comment thread tests/fast_int.cpp Outdated
}

// unsigned pointer test #1 (string behind numbers)
const std::vector<std::string> unsigned_pointer_test_1 { "1001 with text" };
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't need to be vectors if there's only one element in them

Comment thread tests/fast_int.cpp Outdated
}

// int out of range error test
const std::vector<std::string> int_out_of_range_test{ "2000000000000000000000" };
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some more tests here, especially when the numbers are just outside range (like int_max + 1 or int_min -1). these are a bit tougher to catch

Comment thread tests/fast_int.cpp Outdated
unsigned basic tests - numbers only, numbers with strings behind, decimals
int invalid tests - strings only, strings with numbers behind, space in front of number, plus sign in front of number
unsigned invalid tests - strings only, strings with numbers behind, space in front of number, plus/minus sign in front of number
int out of range tests - numbers exceeding int bit size (Note: out of range errors for 8, 16, 32, and 64 bits have not been tested)
Copy link
Copy Markdown
Owner

@mayawarrier mayawarrier Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out_of_range was the nastiest to get right and I'm not 100% sure it's correct since I'm using a few handmade lookup tables to do it.
can you add test cases for every base for 64-bit (signed and unsigned)?

Marvin and others added 2 commits December 12, 2023 13:59
…ts, out of range errors for all bases (64 bit only), and fixed some test cases
Comment thread tests/fast_int.cpp
"ACD772JNC9L0L8",
"-ACD772JNC9L0L9",
"64IE1FOCNN5G78",
"-64IE1FOCNN5G79",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked these numbers, but are some of them just outside the range as well (like int64_min - 1 and int64_max + 1)?

Comment thread tests/fast_int.cpp

// unsigned base 2 test
const std::vector<unsigned> unsigned_base_2_test_expected { 0, 1, 4, 2 };
const std::vector<std::string> unsigned_base_2_test { "0", "1", "100", "010" };
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for every valid test, can you also add cases where the numbers are just within range (like int_min or int_max)

@mayawarrier mayawarrier merged commit a9ee7b0 into mayawarrier:main Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants