mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
Rename average to avg
This commit is contained in:
parent
ed7a62bca3
commit
088901b24f
@ -14,11 +14,11 @@ pub struct SubCommand;
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for SubCommand {
|
||||
fn name(&self) -> &str {
|
||||
"math average"
|
||||
"math avg"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("math average")
|
||||
Signature::build("math avg")
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
@ -49,7 +49,7 @@ impl WholeStreamCommand for SubCommand {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Get the average of a list of numbers",
|
||||
example: "echo [-50 100.0 25] | math average",
|
||||
example: "echo [-50 100.0 25] | math avg",
|
||||
result: Some(vec![UntaggedValue::decimal(25).into()]),
|
||||
}]
|
||||
}
|
@ -35,7 +35,7 @@ impl WholeStreamCommand for Command {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::commands::math::{
|
||||
average::average, max::maximum, min::minimum, sum::summation, utils::MathFunction,
|
||||
avg::average, max::maximum, min::minimum, sum::summation, utils::MathFunction,
|
||||
};
|
||||
use nu_plugin::test_helpers::value::{decimal, int};
|
||||
use nu_protocol::Value;
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub mod average;
|
||||
pub mod avg;
|
||||
pub mod command;
|
||||
pub mod max;
|
||||
pub mod median;
|
||||
@ -6,7 +6,7 @@ pub mod min;
|
||||
pub mod sum;
|
||||
pub mod utils;
|
||||
|
||||
pub use average::SubCommand as MathAverage;
|
||||
pub use avg::SubCommand as MathAverage;
|
||||
pub use command::Command as Math;
|
||||
pub use max::SubCommand as MathMaximum;
|
||||
pub use median::SubCommand as MathMedian;
|
||||
|
@ -7,7 +7,7 @@ fn can_average_numbers() {
|
||||
r#"
|
||||
open sgml_description.json
|
||||
| get glossary.GlossDiv.GlossList.GlossEntry.Sections
|
||||
| math average
|
||||
| math avg
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
@ -19,7 +19,7 @@ fn can_average_numbers() {
|
||||
fn can_average_bytes() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"ls | sort-by name | skip 1 | first 2 | get size | math average | format \"{$it}\" | echo $it"
|
||||
"ls | sort-by name | skip 1 | first 2 | get size | math avg | format \"{$it}\" | echo $it"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1.6 KB");
|
@ -1,4 +1,4 @@
|
||||
mod average;
|
||||
mod avg;
|
||||
mod median;
|
||||
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
@ -3,7 +3,7 @@
|
||||
Mathematical functions that generally only operate on a list of numbers (integers, decimals, bytes) and tables.
|
||||
Currently the following functions are implemented:
|
||||
|
||||
* `math average`: Finds the average of a list of numbers or tables
|
||||
* `math avg`: Finds the average of a list of numbers or tables
|
||||
* `math min`: Finds the minimum within a list of numbers or tables
|
||||
* `math max`: Finds the maximum within a list of numbers or tables
|
||||
* `math sum`: Finds the sum of a list of numbers or tables
|
||||
@ -44,7 +44,7 @@ To get the average of the file sizes in a directory, simply pipe the size column
|
||||
```
|
||||
|
||||
```shell
|
||||
> ls | get size | math average
|
||||
> ls | get size | math avg
|
||||
───┬────────
|
||||
0 │ 7.2 KB
|
||||
───┴────────
|
||||
@ -108,7 +108,7 @@ To get the average of the file sizes in a directory, simply pipe the size column
|
||||
```
|
||||
|
||||
```shell
|
||||
> pwd | split row / | size | math average
|
||||
> pwd | split row / | size | math avg
|
||||
────────────┬────────
|
||||
lines │ 0.0000
|
||||
words │ 1.0000
|
||||
@ -129,7 +129,7 @@ To get the sum of the characters that make up your present working directory.
|
||||
`math` functions are aggregation functions so empty lists are invalid
|
||||
|
||||
```shell
|
||||
> echo [] | math average
|
||||
> echo [] | math avg
|
||||
error: Error: Unexpected: Cannot perform aggregate math operation on empty data
|
||||
```
|
||||
|
||||
@ -137,6 +137,6 @@ Note `math` functions only work on list of numbers (integers, decimals, bytes) a
|
||||
then unexpected results can occur.
|
||||
|
||||
```shell
|
||||
> echo [1 2 a ] | math average
|
||||
> echo [1 2 a ] | math avg
|
||||
0
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user