Skip to content

Commit

Permalink
tests: add frequency --pct-dec-places tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jqnatividad committed Apr 25, 2024
1 parent 17de4fe commit 27bb63b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/test_frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,40 @@ fn frequency_limit() {
assert_eq!(got, expected);
}

#[test]
fn frequency_pct_dec_places() {
let (wrk, mut cmd) = setup("frequency_pct_dec_places");
cmd.args(["--limit", "1"]).args(["--pct-dec-places", "3"]);

let mut got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
got.sort();
let expected = vec![
svec!["field", "value", "count", "percentage"],
svec!["h1", "Other (3)", "3", "42.857"],
svec!["h1", "a", "4", "57.143"],
svec!["h2", "Other (3)", "4", "57.143"],
svec!["h2", "z", "3", "42.857"],
];
assert_eq!(got, expected);
}

#[test]
fn frequency_neg_pct_dec_places() {
let (wrk, mut cmd) = setup("frequency_neg_pct_dec_places");
cmd.args(["--limit", "1"]).args(["--pct-dec-places", "-4"]);

let mut got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
got.sort();
let expected = vec![
svec!["field", "value", "count", "percentage"],
svec!["h1", "Other (3)", "3", "42.8571"],
svec!["h1", "a", "4", "57.1429"],
svec!["h2", "Other (3)", "4", "57.1429"],
svec!["h2", "z", "3", "42.8571"],
];
assert_eq!(got, expected);
}

#[test]
fn frequency_limit_no_other() {
let (wrk, mut cmd) = setup("frequency_limit_no_other");
Expand Down

0 comments on commit 27bb63b

Please sign in to comment.