use egui_kittest::wgpu::{create_render_state, default_wgpu_setup};
use rsplot::Plot1D;
use rsplot::egui::Color32;
#[test]
fn y_log_toggle_snaps_to_positive_data_range() {
let rs = create_render_state(default_wgpu_setup());
rsplot::install(&rs);
let mut plot = Plot1D::new(&rs, 0);
let xs: Vec<f64> = (0..=10).map(|i| i as f64).collect();
let ys: Vec<f64> = xs.iter().map(|x| x - 5.0).collect();
let _ = plot.add_curve(&xs, &ys, Color32::RED);
let (_, _, y0, y1) = plot.plot().limits;
assert_eq!((y0, y1), (-5.0, 5.0), "auto refit before the toggle");
plot.set_y_log(true);
let (_, _, y0, y1) = plot.plot().limits;
assert_eq!((y0, y1), (1.0, 5.0), "positive-data refit at toggle time");
}
#[test]
fn x_log_toggle_with_no_positive_data_lands_on_1_100() {
let rs = create_render_state(default_wgpu_setup());
rsplot::install(&rs);
let mut plot = Plot1D::new(&rs, 0);
let xs: Vec<f64> = (0..=10).map(|i| -(i as f64)).collect();
let ys: Vec<f64> = (0..=10).map(|i| i as f64 + 1.0).collect();
let _ = plot.add_curve(&xs, &ys, Color32::RED);
plot.set_x_log(true);
let (x0, x1, _, _) = plot.plot().limits;
assert_eq!((x0, x1), (1.0, 100.0));
}
#[test]
fn keep_aspect_toggle_forces_reset_zoom_once() {
let rs = create_render_state(default_wgpu_setup());
rsplot::install(&rs);
let mut plot = Plot1D::new(&rs, 0);
let xs: Vec<f64> = (0..=10).map(|i| i as f64).collect();
let ys: Vec<f64> = xs.clone();
let _ = plot.add_curve(&xs, &ys, Color32::RED);
let home = plot.plot().limits;
plot.set_graph_x_limits(2.0, 3.0);
assert_ne!(plot.plot().limits, home);
plot.set_keep_data_aspect_ratio(true);
assert_eq!(plot.plot().limits, home, "changed flag forces a reset zoom");
plot.set_graph_x_limits(2.0, 3.0);
let zoomed = plot.plot().limits;
plot.set_keep_data_aspect_ratio(true);
assert_eq!(plot.plot().limits, zoomed, "unchanged flag is a no-op");
}