MCPcopy Create free account
hub / github.com/cpmech/plotpy / test_subplot

Function test_subplot

tests/test_subplot.rs:9–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7
8#[test]
9fn test_subplot() -> Result<(), StrError> {
10 // curves
11 let mut curve1 = Curve::new();
12 let mut curve2 = Curve::new();
13 let x = &[1.0, 2.0, 3.0, 4.0];
14 let y = &[1.0, 1.424, 1.732, 2.0];
15 let z = &[1.0, 4.0, 9.0, 16.0];
16 curve1.draw(x, y);
17 curve2.draw(x, z);
18
19 // plot and subplots
20 let mut plot = Plot::new();
21 plot.set_subplot(1, 2, 1).add(&curve1);
22 plot.set_subplot(1, 2, 2).add(&curve2);
23
24 // save figure
25 let path = Path::new(OUT_DIR).join("integ_subplot_before.svg");
26 plot.save(&path)?;
27
28 // check number of lines
29 let file = File::open(path).map_err(|_| "cannot open file")?;
30 let buffered = BufReader::new(file);
31 let lines_iter = buffered.lines();
32 let n = lines_iter.count();
33 assert!(n > 600);
34 assert!(n < 650);
35
36 // clear the current axes
37 plot.set_subplot(1, 2, 1).clear_current_axes();
38
39 // save figure again
40 let path = Path::new(OUT_DIR).join("integ_subplot_after.svg");
41 plot.save(&path)?;
42
43 // check number of lines
44 let file = File::open(path).map_err(|_| "cannot open file")?;
45 let buffered = BufReader::new(file);
46 let lines_iter = buffered.lines();
47 let n = lines_iter.count();
48 assert!(n > 650);
49 assert!(n < 680);
50 Ok(())
51}
52
53#[test]
54fn test_gridspec_1() -> Result<(), StrError> {

Callers

nothing calls this directly

Calls 5

set_subplotMethod · 0.80
saveMethod · 0.80
clear_current_axesMethod · 0.80
drawMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected