use proptest::prelude::*;
use proptest::test_runner::TestRunner;
#[test]
fn bezier_formula_never_panics_for_any_f64() {
let mut runner = TestRunner::default();
runner
.run(
&(
any::<f64>(),
any::<f64>(),
any::<f64>(),
any::<f64>(),
any::<f64>(),
),
|(x0, _y0, x1, _y1, t)| {
let t = t.abs() % 1.0;
let u = 1.0 - t;
let cx1 = x0 + (x1 - x0) * 0.3;
let cx2 = x0 + (x1 - x0) * 0.7;
let _x =
u * u * u * x0 + 3.0 * u * u * t * cx1 + 3.0 * u * t * t * cx2 + t * t * t * x1;
prop_assert!(_x.is_finite() || _x.is_nan());
Ok(())
},
)
.unwrap();
}
#[test]
fn ease_function_range_0_to_1() {
let mut runner = TestRunner::default();
runner
.run(&(0.0f64..1.0f64), |t| {
let ease = (std::f64::consts::PI * t).sin();
prop_assert!((0.0..=1.0).contains(&ease));
Ok(())
})
.unwrap();
}
#[test]
fn bezier_endpoints_exact_for_any_control_points() {
let mut runner = TestRunner::default();
runner
.run(
&(any::<f64>(), any::<f64>(), any::<f64>(), any::<f64>()),
|(x0, y0, x1, y1)| {
let t0 = 0.0;
let u0 = 1.0 - t0;
let cx1 = x0;
let cy1 = y0;
let cx2 = x1;
let cy2 = y1;
let bx0 = u0 * u0 * u0 * x0
+ 3.0 * u0 * u0 * t0 * cx1
+ 3.0 * u0 * t0 * t0 * cx2
+ t0 * t0 * t0 * x1;
let by0 = u0 * u0 * u0 * y0
+ 3.0 * u0 * u0 * t0 * cy1
+ 3.0 * u0 * t0 * t0 * cy2
+ t0 * t0 * t0 * y1;
prop_assert_eq!(bx0, x0);
prop_assert_eq!(by0, y0);
Ok(())
},
)
.unwrap();
}
#[test]
fn scroll_direction_is_copy() {
let d = captchaforge::behavior::ScrollDirection::Down;
let d2 = d;
assert_eq!(d, d2);
}