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

Function test_plot_multiple_of_pi

tests/test_plot.rs:299–342  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

297
298#[test]
299fn test_plot_multiple_of_pi() -> Result<(), StrError> {
300 // configure curve
301 let mut cos_curve = Curve::new();
302 let mut sin_curve = Curve::new();
303 cos_curve.set_line_width(2.0);
304 sin_curve.set_line_width(2.0).set_line_color("#cd0000");
305
306 // add points
307 const N: usize = 30;
308 cos_curve.points_begin();
309 sin_curve.points_begin();
310 for i in 0..N {
311 let u = (i as f64) * 2.0 * PI / ((N - 1) as f64);
312 cos_curve.points_add(u, f64::cos(u));
313 sin_curve.points_add(f64::sin(u), u);
314 }
315 cos_curve.points_end();
316 sin_curve.points_end();
317
318 // configure plot
319 let mut plot = Plot::new();
320 plot.set_gaps(0.3, 0.0).set_figure_size_points(600.0, 250.0);
321
322 // add cos curve to plot
323 plot.set_subplot(1, 2, 1);
324 plot.add(&cos_curve).grid_and_labels("x", "y=cos(x)");
325 plot.set_ticks_x_multiple_of_pi(0.0);
326
327 // add sin curve to plot
328 plot.set_subplot(1, 2, 2);
329 plot.add(&sin_curve).grid_and_labels("x=sin(y)", "y");
330 plot.set_ticks_y_multiple_of_pi(0.0);
331
332 // save figure
333 let path = Path::new(OUT_DIR).join("integ_plot_multiple_of_pi.svg");
334 plot.set_show_errors(true).save(&path)?;
335
336 // check number of lines
337 let file = File::open(path).map_err(|_| "cannot open file")?;
338 let buffered = BufReader::new(file);
339 let lines_iter = buffered.lines();
340 assert!(lines_iter.count() > 1060);
341 Ok(())
342}
343
344#[test]
345fn test_plot_extra_functionality() -> Result<(), StrError> {

Callers

nothing calls this directly

Calls 14

points_beginMethod · 0.80
points_addMethod · 0.80
points_endMethod · 0.80
set_gapsMethod · 0.80
set_subplotMethod · 0.80
grid_and_labelsMethod · 0.80
saveMethod · 0.80
set_show_errorsMethod · 0.80
set_line_widthMethod · 0.45

Tested by

no test coverage detected