From c9c67a2ecfbfd0613acdc3243eb79b256a9eb391 Mon Sep 17 00:00:00 2001 From: Dorival Pedroso Date: Thu, 19 Sep 2024 11:44:31 +1000 Subject: [PATCH] Add boxplot test --- examples/README.md | 1 + figures/integ_boxplot_3.svg | 1211 +++++++++++++++++++++++++++++++++++ tests/test_boxplot.rs | 45 ++ 3 files changed, 1257 insertions(+) create mode 100644 figures/integ_boxplot_3.svg diff --git a/examples/README.md b/examples/README.md index 1c4d411..fb932fb 100644 --- a/examples/README.md +++ b/examples/README.md @@ -19,6 +19,7 @@ Some output of integration tests are shown below. ![boxplot](https://raw.githubusercontent.com/cpmech/plotpy/main/figures/integ_boxplot_1.svg) ![boxplot](https://raw.githubusercontent.com/cpmech/plotpy/main/figures/integ_boxplot_2.svg) +![boxplot](https://raw.githubusercontent.com/cpmech/plotpy/main/figures/integ_boxplot_3.svg) ## Canvas diff --git a/figures/integ_boxplot_3.svg b/figures/integ_boxplot_3.svg new file mode 100644 index 0000000..527b0c6 --- /dev/null +++ b/figures/integ_boxplot_3.svg @@ -0,0 +1,1211 @@ + + + + + + + + 2024-09-19T11:43:38.272309 + image/svg+xml + + + Matplotlib v3.6.3, https://matplotlib.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_boxplot.rs b/tests/test_boxplot.rs index 96ffa34..6db317a 100644 --- a/tests/test_boxplot.rs +++ b/tests/test_boxplot.rs @@ -91,3 +91,48 @@ fn test_boxplot_2() -> Result<(), StrError> { assert!(c > 950 && c < 1000); Ok(()) } + +#[test] +fn test_boxplot_3() -> Result<(), StrError> { + let data = vec![ + // A B C D E ← matrix: columns are series + // nested: rows are series + // ↓ + vec![1.0, 2.0, 3.0, 4.0, 5.0], // A + vec![1.1, 2.1, 3.1, 4.1, 5.1], // B + vec![1.2, 2.2, 3.2, 4.2, 5.2], // C + vec![1.3, 2.3, 3.3, 4.3, 5.3], // D + vec![1.4, 2.4, 3.4, 4.4, 5.4], // E + ]; + + let ticks = [1, 2, 3, 4, 5]; + let labels = ["A", "B", "C", "D", "E"]; + + let mut boxes_nes = Boxplot::new(); + boxes_nes.draw(&data); + + let mut boxes_mat = Boxplot::new(); + boxes_mat.draw_mat(&data); + + let mut plot = Plot::new(); + plot.set_subplot(1, 2, 1) + .set_title("nested") + .add(&boxes_nes) + .set_ticks_x_labels(&ticks, &labels) + .set_subplot(1, 2, 2) + .set_title("matrix") + .add(&boxes_mat) + .set_ticks_x_labels(&ticks, &labels); + + // save figure + let path = Path::new(OUT_DIR).join("integ_boxplot_3.svg"); + plot.set_figure_size_points(650.0, 300.0).save(&path)?; + + // check number of lines + let file = File::open(path).map_err(|_| "cannot open file")?; + let buffered = BufReader::new(file); + let lines_iter = buffered.lines(); + let c = lines_iter.count(); + assert!(c > 1180 && c < 1260); + Ok(()) +}