()
| 297 | |
| 298 | #[test] |
| 299 | fn 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] |
| 345 | fn test_plot_extra_functionality() -> Result<(), StrError> { |
nothing calls this directly
no test coverage detected