mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 13:37:48 +00:00
Merge pull request #5980 from BenWiederhake/dev-shuf-number-speed
shuf: Fix OOM crash for huge number ranges
This commit is contained in:
commit
8301a8e5be
3 changed files with 368 additions and 20 deletions
|
@ -88,6 +88,99 @@ fn test_zero_termination_multi() {
|
|||
assert_eq!(result_seq, input_seq, "Output is not a permutation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_very_large_range() {
|
||||
let num_samples = 10;
|
||||
let result = new_ucmd!()
|
||||
.arg("-n")
|
||||
.arg(&num_samples.to_string())
|
||||
.arg("-i0-1234567890")
|
||||
.succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let result_seq: Vec<isize> = result
|
||||
.stdout_str()
|
||||
.split('\n')
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
assert_eq!(result_seq.len(), num_samples, "Miscounted output length!");
|
||||
assert!(
|
||||
result_seq.iter().all(|x| (0..=1234567890).contains(x)),
|
||||
"Output includes element not from range: {}",
|
||||
result.stdout_str()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_very_large_range_offset() {
|
||||
let num_samples = 10;
|
||||
let result = new_ucmd!()
|
||||
.arg("-n")
|
||||
.arg(&num_samples.to_string())
|
||||
.arg("-i1234567890-2147483647")
|
||||
.succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let result_seq: Vec<isize> = result
|
||||
.stdout_str()
|
||||
.split('\n')
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
assert_eq!(result_seq.len(), num_samples, "Miscounted output length!");
|
||||
assert!(
|
||||
result_seq
|
||||
.iter()
|
||||
.all(|x| (1234567890..=2147483647).contains(x)),
|
||||
"Output includes element not from range: {}",
|
||||
result.stdout_str()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_very_high_range_full() {
|
||||
let input_seq = vec![
|
||||
2147483641, 2147483642, 2147483643, 2147483644, 2147483645, 2147483646, 2147483647,
|
||||
];
|
||||
let result = new_ucmd!().arg("-i2147483641-2147483647").succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let mut result_seq: Vec<isize> = result
|
||||
.stdout_str()
|
||||
.split('\n')
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
result_seq.sort_unstable();
|
||||
assert_eq!(result_seq, input_seq, "Output is not a permutation");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_repeat() {
|
||||
let num_samples = 500;
|
||||
let result = new_ucmd!()
|
||||
.arg("-r")
|
||||
.arg("-n")
|
||||
.arg(&num_samples.to_string())
|
||||
.arg("-i12-34")
|
||||
.succeeds();
|
||||
result.no_stderr();
|
||||
|
||||
let result_seq: Vec<isize> = result
|
||||
.stdout_str()
|
||||
.split('\n')
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse().unwrap())
|
||||
.collect();
|
||||
assert_eq!(result_seq.len(), num_samples, "Miscounted output length!");
|
||||
assert!(
|
||||
result_seq.iter().all(|x| (12..=34).contains(x)),
|
||||
"Output includes element not from range: {}",
|
||||
result.stdout_str()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_input() {
|
||||
let result = new_ucmd!().pipe_in(vec![]).succeeds();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue