2020-06-18 23:37:18 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn median_numbers_with_even_rows() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-18 23:37:18 +02:00
|
|
|
r#"
|
|
|
|
echo [10 6 19 21 4]
|
|
|
|
| math median
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "10")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn median_numbers_with_odd_rows() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-18 23:37:18 +02:00
|
|
|
r#"
|
|
|
|
echo [3 8 9 12 12 15]
|
|
|
|
| math median
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "10.5")
|
|
|
|
}
|
2020-06-20 06:34:36 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn median_mixed_numbers() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-20 06:34:36 +02:00
|
|
|
r#"
|
|
|
|
echo [-11.5 -13.5 10]
|
|
|
|
| math median
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "-11.5")
|
|
|
|
}
|