MCPcopy Index your code
hub / github.com/cpmech/plotpy / test_barplot_2

Function test_barplot_2

tests/test_barplot.rs:36–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34
35#[test]
36fn 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]
80fn test_barplot_3() -> Result<(), StrError> {

Callers

nothing calls this directly

Calls 11

set_with_textMethod · 0.80
draw_with_strMethod · 0.80
set_bottomMethod · 0.80
saveMethod · 0.80
legendMethod · 0.80
set_extraMethod · 0.45
set_widthMethod · 0.45
set_colorsMethod · 0.45
set_labelMethod · 0.45
addMethod · 0.45
set_titleMethod · 0.45

Tested by

no test coverage detected