-
Notifications
You must be signed in to change notification settings - Fork 12.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
Migrate unit tests of btree collections to their native breeding ground #75531
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3024,3 +3024,6 @@ impl<K: Ord, V, I: Iterator<Item = (K, V)>> Iterator for MergeIter<K, V, I> { | |
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests; |
14 changes: 9 additions & 5 deletions
14
library/alloc/tests/btree/map.rs → .../alloc/src/collections/btree/map/tests.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use super::*; | ||
|
||
#[test] | ||
fn test_splitpoint() { | ||
for idx in 0..=CAPACITY { | ||
let (middle_kv_idx, insertion) = splitpoint(idx); | ||
|
||
// Simulate performing the split: | ||
let mut left_len = middle_kv_idx; | ||
let mut right_len = CAPACITY - middle_kv_idx - 1; | ||
match insertion { | ||
InsertionPlace::Left(edge_idx) => { | ||
assert!(edge_idx <= left_len); | ||
left_len += 1; | ||
} | ||
InsertionPlace::Right(edge_idx) => { | ||
assert!(edge_idx <= right_len); | ||
right_len += 1; | ||
} | ||
} | ||
assert!(left_len >= MIN_LEN); | ||
assert!(right_len >= MIN_LEN); | ||
assert!(left_len + right_len == CAPACITY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::collections::BTreeSet; | ||
|
||
#[test] | ||
fn test_hash() { | ||
use crate::hash; | ||
|
||
let mut x = BTreeSet::new(); | ||
let mut y = BTreeSet::new(); | ||
|
||
x.insert(1); | ||
x.insert(2); | ||
x.insert(3); | ||
|
||
y.insert(3); | ||
y.insert(2); | ||
y.insert(1); | ||
|
||
assert_eq!(hash(&x), hash(&y)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
Can you say more about why this didn't migrate? (E.g. the error log)
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.
The
hash
function is defined in the integration test itself and uses the hashmap crate or whatever contains it.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.
I didn't really look into what
DefaultHasher
is, it looks foreign enough for me to say it's an integration test.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.
Or rather, to say it's not a btree unit test. In my book, it could be a hashmap unit test, built on top of btree.
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.
hm okay, seems fine to leave it external, though I suspect we could internalize it without too much trouble if we really wanted to.
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.
Oh, I see: it tests the default
Hash
implementation onBTreeSet
. Why not test the non-defaultHash
implementation onBTreeMap
for a change?