-
Notifications
You must be signed in to change notification settings - Fork 2
test: ensure rust and cpp compression matches #32
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
Merged
nyurik
merged 2 commits into
fast-pack:main
from
Weixing-Zhang:test/rust-and-cpp-compression-matches
May 7, 2025
Merged
Changes from 1 commit
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 hidden or 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 hidden or 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,45 @@ | ||
| #![cfg(all(feature = "rust", feature = "cpp"))] | ||
|
||
|
|
||
| use rand::rngs::StdRng; | ||
| use rand::Rng as _; | ||
| use rand::SeedableRng as _; | ||
|
|
||
| pub fn get_test_cases(n: usize) -> Vec<Vec<u32>> { | ||
| let mut rng = StdRng::seed_from_u64(14); | ||
|
|
||
| vec![ | ||
| // Zeroes | ||
| vec![0u32; n], | ||
| // Same non-zero | ||
| vec![14u32; n], | ||
| // Ascending values | ||
| (0..n).map(|i| i as u32).collect::<Vec<u32>>(), | ||
| // Descending values | ||
| (0..n).rev().map(|i| i as u32).collect::<Vec<u32>>(), | ||
| // Bit-flipping pattern | ||
| (0..n) | ||
| .map(|i| ((i as u32) * 32) ^ ((i as u32) >> 1)) | ||
| .collect::<Vec<u32>>(), | ||
| // Alternating large and small values | ||
| (0..n) | ||
| .map(|i| { | ||
| let ui = i as u32; | ||
| if ui % 2 == 0 { | ||
| 1 << 30 | ||
| } else { | ||
| 3 | ||
| } | ||
| }) | ||
| .collect::<Vec<u32>>(), | ||
| // Random u32 values | ||
| (0..n) | ||
| .map(|_| rng.random_range(0..(1 << 31))) | ||
| .collect::<Vec<u32>>(), | ||
| // Spike in the middle | ||
| (0..n) | ||
| .map(|i| if i == n / 2 { u32::MAX } else { 1 }) | ||
| .collect::<Vec<u32>>(), | ||
| // An empty vector | ||
| Vec::new(), | ||
| ] | ||
| } | ||
Oops, something went wrong.
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.
while totally not critical, and probably good for another PR, but it seems it might benefit us in the future to come up with some trait-based API that is the same for both rust and cpp implementation... ideas are welcome
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.
Completely agreed. For now, I need to apply a small workaround due to the interface between the rust-native implementation and the rust wrapper. A key issue is that the current rust-native code does not support arbitrary input lengths. The cpp implementation appears to tolerate such cases. I have added this to my to-do list once I better understand the algorithm.