()
| 34 | |
| 35 | #[test] |
| 36 | fn test_barplot_2() -> Result<(), StrError> { |
| 37 | // data |
| 38 | let species = ["Adelie", "Chinstrap", "Gentoo"]; |
| 39 | let sex_counts = HashMap::from([ |
| 40 | ("Male", ([73.0, 34.0, 61.0], ["red", "green", "blue"])), |
| 41 | ("Female", ([73.0, 34.0, 58.0], ["#DE3163", "#40E0D0", "#6495ED"])), |
| 42 | ]); |
| 43 | |
| 44 | // barplot object and options |
| 45 | let mut bar = Barplot::new(); |
| 46 | bar.set_with_text("center") |
| 47 | .set_width(0.6) |
| 48 | .set_extra("edgecolor='black'"); |
| 49 | |
| 50 | // draw bars |
| 51 | let mut bottom = [0.0, 0.0, 0.0]; |
| 52 | for (sex, (sex_count, colors)) in &sex_counts { |
| 53 | bar.set_label(sex) |
| 54 | .set_colors(colors) |
| 55 | .set_bottom(&bottom) |
| 56 | .draw_with_str(&species, sex_count); |
| 57 | for i in 0..sex_count.len() { |
| 58 | bottom[i] += sex_count[i]; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | // plot |
| 63 | let mut plot = Plot::new(); |
| 64 | plot.add(&bar); |
| 65 | |
| 66 | // save figure |
| 67 | let path = Path::new(OUT_DIR).join("integ_barplot_2.svg"); |
| 68 | plot.set_title("Number of penguins by sex").legend().save(&path)?; |
| 69 | |
| 70 | // check number of lines |
| 71 | let file = File::open(path).map_err(|_| "cannot open file")?; |
| 72 | let buffered = BufReader::new(file); |
| 73 | let lines_iter = buffered.lines(); |
| 74 | let c = lines_iter.count(); |
| 75 | assert!(c > 1180 && c < 1200); |
| 76 | Ok(()) |
| 77 | } |
| 78 | |
| 79 | #[test] |
| 80 | fn test_barplot_3() -> Result<(), StrError> { |
nothing calls this directly
no test coverage detected