mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
Implement histogram command (#5518)
* finish histogram * adjust comment * add test for histogram * add Date to test * move hashable value back inside chart package
This commit is contained in:
@ -2,10 +2,40 @@ use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn summarizes_by_column_given() {
|
||||
Playground::setup("histogram_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at
|
||||
Andrés,Robalino,Ecuador
|
||||
Jonathan,Turner,Estados Unidos
|
||||
Yehuda,Katz,Estados Unidos
|
||||
"#,
|
||||
)]);
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| histogram rusty_at countries --percentage-type relative
|
||||
| where rusty_at == "Ecuador"
|
||||
| get countries
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"**************************************************"
|
||||
);
|
||||
// 50%
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn summarizes_by_column_given_with_normalize_percentage() {
|
||||
Playground::setup("histogram_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
@ -24,19 +54,15 @@ fn summarizes_by_column_given() {
|
||||
| histogram rusty_at countries
|
||||
| where rusty_at == "Ecuador"
|
||||
| get countries
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"**************************************************"
|
||||
);
|
||||
// 50%
|
||||
assert_eq!(actual.out, "*********************************");
|
||||
// 33%
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn summarizes_by_values() {
|
||||
Playground::setup("histogram_test_2", |dirs, sandbox| {
|
||||
@ -58,6 +84,7 @@ fn summarizes_by_values() {
|
||||
| histogram
|
||||
| where value == "Estados Unidos"
|
||||
| get count
|
||||
| get 0
|
||||
"#
|
||||
));
|
||||
|
||||
@ -65,8 +92,6 @@ fn summarizes_by_values() {
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn help() {
|
||||
Playground::setup("histogram_test_3", |dirs, _sandbox| {
|
||||
@ -96,22 +121,38 @@ fn help() {
|
||||
})
|
||||
}
|
||||
|
||||
// FIXME: jt: needs more work
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn count() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
|
||||
| histogram bit
|
||||
| histogram bit --percentage-type relative
|
||||
| sort-by count
|
||||
| reject frequency
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let bit_json = r#"[{"bit":"1","count":2,"percentage":"33.33%"},{"bit":"0","count":6,"percentage":"100.00%"}]"#;
|
||||
let bit_json = r#"[ { "bit": 1, "count": 2, "percentage": "33.33%" }, { "bit": 0, "count": 6, "percentage": "100.00%" }]"#;
|
||||
|
||||
assert_eq!(actual.out, bit_json);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_with_normalize_percentage() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [[bit]; [1] [0] [0] [0] [0] [0] [0] [1]]
|
||||
| histogram bit --percentage-type normalize
|
||||
| sort-by count
|
||||
| reject frequency
|
||||
| to json
|
||||
"#
|
||||
));
|
||||
|
||||
let bit_json = r#"[ { "bit": 1, "count": 2, "percentage": "25.00%" }, { "bit": 0, "count": 6, "percentage": "75.00%" }]"#;
|
||||
|
||||
assert_eq!(actual.out, bit_json);
|
||||
}
|
||||
|
Reference in New Issue
Block a user