mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
sort: Add a GNU-style Random Sorter (#1922)
This commit is contained in:
parent
8cc7a90d7c
commit
da5f2f3a6c
4 changed files with 261 additions and 44 deletions
|
@ -2,22 +2,43 @@ use crate::common::util::*;
|
|||
|
||||
#[test]
|
||||
fn test_numeric_floats_and_ints() {
|
||||
test_helper("numeric_floats_and_ints", "-n");
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1\n-8\n1.04\n-1";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8\n-1\n1\n1.04\n1.444\n8.013\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats() {
|
||||
test_helper("numeric_floats", "-n");
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8.90880\n-.05\n1.040000000\n1.444\n1.58590\n8.013\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_floats_with_nan() {
|
||||
test_helper("numeric_floats_with_nan", "-n");
|
||||
for numeric_sort_param in vec!["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n1.0/0.0\n1.58590\n-8.90880\n1.040000000\n-.05";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8.90880\n-.05\n1.0/0.0\n1.040000000\n1.444\n1.58590\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unfixed_floats() {
|
||||
test_helper("numeric_unfixed_floats", "-n");
|
||||
test_helper("numeric_fixed_floats", "-n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -32,12 +53,26 @@ fn test_numeric_unsorted_ints() {
|
|||
|
||||
#[test]
|
||||
fn test_human_block_sizes() {
|
||||
test_helper("human_block_sizes", "-h");
|
||||
for human_numeric_sort_param in vec!["-h", "--human-numeric-sort"] {
|
||||
let input = "8981K\n909991M\n-8T\n21G\n0.8M";
|
||||
new_ucmd!()
|
||||
.arg(human_numeric_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("-8T\n0.8M\n8981K\n21G\n909991M\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_month_default() {
|
||||
test_helper("month_default", "-M");
|
||||
for month_sort_param in vec!["-M", "--month-sort"] {
|
||||
let input = "JAn\nMAY\n000may\nJun\nFeb";
|
||||
new_ucmd!()
|
||||
.arg(month_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("000may\nJAn\nFeb\nMAY\nJun\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -47,12 +82,23 @@ fn test_month_stable() {
|
|||
|
||||
#[test]
|
||||
fn test_default_unsorted_ints() {
|
||||
test_helper("default_unsorted_ints", "");
|
||||
let input = "9\n1909888\n000\n1\n2";
|
||||
new_ucmd!()
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("000\n1\n1909888\n2\n9\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_numeric_unique_ints() {
|
||||
test_helper("numeric_unsorted_ints_unique", "-nu");
|
||||
for numeric_unique_sort_param in vec!["-nu"] {
|
||||
let input = "9\n9\n8\n1\n";
|
||||
new_ucmd!()
|
||||
.arg(numeric_unique_sort_param)
|
||||
.pipe_in(input)
|
||||
.succeeds()
|
||||
.stdout_only("1\n8\n9\n");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue