assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&f32::INFINITY));
assert_eq!(Ordering::Less, (-s_nan()).total_cmp(&s_nan()));
}
+
+#[test]
+fn test_lerp_exact() {
+ // simple values
+ assert_eq!(f32::lerp(0.0, 2.0, 4.0), 2.0);
+ assert_eq!(f32::lerp(1.0, 2.0, 4.0), 4.0);
+
+ // boundary values
+ assert_eq!(f32::lerp(0.0, f32::MIN, f32::MAX), f32::MIN);
+ assert_eq!(f32::lerp(1.0, f32::MIN, f32::MAX), f32::MAX);
+}
+
+#[test]
+fn test_lerp_consistent() {
+ assert_eq!(f32::lerp(f32::MAX, f32::MIN, f32::MIN), f32::MIN);
+ assert_eq!(f32::lerp(f32::MIN, f32::MAX, f32::MAX), f32::MAX);
+
+ // as long as t is finite, a/b can be infinite
+ assert_eq!(f32::lerp(f32::MAX, f32::NEG_INFINITY, f32::NEG_INFINITY), f32::NEG_INFINITY);
+ assert_eq!(f32::lerp(f32::MIN, f32::INFINITY, f32::INFINITY), f32::INFINITY);
+}
+
+#[test]
+fn test_lerp_nan_infinite() {
+ // non-finite t is not NaN if a/b different
+ assert!(!f32::lerp(f32::INFINITY, f32::MIN, f32::MAX).is_nan());
+ assert!(!f32::lerp(f32::NEG_INFINITY, f32::MIN, f32::MAX).is_nan());
+}
+
+#[test]
+fn test_lerp_values() {
+ // just a few basic values
+ assert_eq!(f32::lerp(0.25, 1.0, 2.0), 1.25);
+ assert_eq!(f32::lerp(0.50, 1.0, 2.0), 1.50);
+ assert_eq!(f32::lerp(0.75, 1.0, 2.0), 1.75);
+}
+
+#[test]
+fn test_lerp_monotonic() {
+ // near 0
+ let below_zero = f32::lerp(-f32::EPSILON, f32::MIN, f32::MAX);
+ let zero = f32::lerp(0.0, f32::MIN, f32::MAX);
+ let above_zero = f32::lerp(f32::EPSILON, f32::MIN, f32::MAX);
+ assert!(below_zero <= zero);
+ assert!(zero <= above_zero);
+ assert!(below_zero <= above_zero);
+
+ // near 0.5
+ let below_half = f32::lerp(0.5 - f32::EPSILON, f32::MIN, f32::MAX);
+ let half = f32::lerp(0.5, f32::MIN, f32::MAX);
+ let above_half = f32::lerp(0.5 + f32::EPSILON, f32::MIN, f32::MAX);
+ assert!(below_half <= half);
+ assert!(half <= above_half);
+ assert!(below_half <= above_half);
+
+ // near 1
+ let below_one = f32::lerp(1.0 - f32::EPSILON, f32::MIN, f32::MAX);
+ let one = f32::lerp(1.0, f32::MIN, f32::MAX);
+ let above_one = f32::lerp(1.0 + f32::EPSILON, f32::MIN, f32::MAX);
+ assert!(below_one <= one);
+ assert!(one <= above_one);
+ assert!(below_one <= above_one);
+}