-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: test bottom-up merge sort in URLSearchParams #11399
Conversation
@@ -82,3 +82,34 @@ const { test, assert_array_equals } = common.WPT; | |||
} | |||
}, 'URL parse and sort: ' + val.input); | |||
}); | |||
|
|||
// Test bottom-up iterative stable merge sort | |||
const params = {input: '', output: []}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am reading correctly the test part below just duplicates the code above? Then we can probably just construct the params
first and then put it in the array literal that's being forEach
ed above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's nice. I've updated it :)
e653c27
to
cca745a
Compare
const tests = [{input: '', output: []}]; | ||
for (let i = 0; 50 > i; i++) { | ||
tests[0].input += 'a=b&'; | ||
tests[0].output.push(['a', 'b']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm..so looks like this doesn't actually catch a mistake in the implementation because we are sorting identical pairs...maybe we can generate the keys on the fly, pseudo-shuffle them, then compared to another original copy to make sure they are sorted properly?
const tests = [{input: '', output: []}];
const pairs = [];
for (let i = 10; i < 60; i++) {
pairs.push([`a${i}`, 'b']);
tests[0].output.push([`a${i}`, 'b']);
}
tests[0].input = pairs.sort(() => Math.random() > 0.5).map((pair) => pair.join('=')).join('&');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right indeed. To use the random list to sort them actually, I've updated it with your comment. Thanks!
cca745a
to
461fea7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
// Test bottom-up iterative stable merge sort | ||
const tests = [{input: '', output: []}]; | ||
const pairs = []; | ||
for (let i = 10; i < 60; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd be more comfortable if there are more than just the threshold number of elements in pairs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds good to me as well. I will replace 60 with 100 later :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've updated.
The bottom-up iterative stable merge sort is called only when the length of provided value is larger than 100. Added a test for it.
461fea7
to
8176dc3
Compare
CI failures are unrelated. |
The bottom-up iterative stable merge sort is called only when the length of provided value is larger than 100. Added a test for it. PR-URL: #11399 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Landed in 1b31ca6 |
The bottom-up iterative stable merge sort is called only when the length of provided value is larger than 100. Added a test for it. PR-URL: nodejs#11399 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Following up for this commit: 02d1e32 to increase the reduced coverage. The bottom-up iterative stable merge sort is called only when the length of provided value is larger than 100. Added a test for it.
This increases the coverage of
internal/url.js
,and the following lines will be covered.
node/lib/internal/url.js
Lines 701 to 727 in e4e7cd5
node/lib/internal/url.js
Lines 886 to 900 in e4e7cd5
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test